Remove support for the "command" encoder
The "command" encoder was mostly intended for use in `%rename` - most uses can be achieved using the "regex" encoder, so we recommend using that instead. The "command" encoder suffers from a number of issues - as the documentation for it admitted, "[it] is extremely slow compared to all the other [encoders] as it involves spawning a separate process and using it for many declarations is not recommended" and that it "should generally be avoided because of performance considerations". But it's also not portable. The design assumes that `/bin/sh` supports `<<<` but that's a bash-specific feature so it doesn't work on platforms where `/bin/sh` is not bash - it fails on Debian, Ubuntu and probably some other Linux distros, plus most non-Linux platforms. Microsoft Windows doesn't even have a /bin/sh as standard. Finally, no escaping of the passed string is done, so it has potential security issues (though at least with %rename the input is limited to valid C/C++ symbol names). Fixes #1806
This commit is contained in:
parent
d47970e2fd
commit
467c530e65
6 changed files with 36 additions and 56 deletions
|
|
@ -1157,47 +1157,14 @@ int Swig_scopename_check(const String *s) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_command()
|
||||
*
|
||||
* Executes a external command via popen with the string as a command
|
||||
* line parameter. For example:
|
||||
*
|
||||
* Printf(stderr,"%(command:sed 's/[a-z]/\U\\1/' <<<)s","hello") -> Hello
|
||||
* Feature removed in SWIG 4.1.0.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#if defined(_MSC_VER)
|
||||
# define popen _popen
|
||||
# define pclose _pclose
|
||||
# if !defined(HAVE_POPEN)
|
||||
# define HAVE_POPEN 1
|
||||
# endif
|
||||
#else
|
||||
# if !defined(_WIN32)
|
||||
/* These Posix functions are not ISO C and so are not always defined in stdio.h */
|
||||
extern FILE *popen(const char *command, const char *type);
|
||||
extern int pclose(FILE *stream);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
String *Swig_string_command(String *s) {
|
||||
String *res = NewStringEmpty();
|
||||
#if defined(HAVE_POPEN)
|
||||
if (Len(s)) {
|
||||
char *command = Char(s);
|
||||
FILE *fp = popen(command, "r");
|
||||
if (fp) {
|
||||
char buffer[1025];
|
||||
while (fscanf(fp, "%1024s", buffer) != EOF) {
|
||||
Append(res, buffer);
|
||||
}
|
||||
pclose(fp);
|
||||
} else {
|
||||
Swig_error("SWIG", Getline(s), "Command encoder fails attempting '%s'.\n", s);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
Swig_error("SWIG", Getline(s), "Command encoder no longer supported - use regex encoder instead.\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_strip()
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue