1
1

tests: avoid use of banned function strncat (#489)

Этот коммит содержится в:
Marc Hoersken 2020-06-22 08:21:26 +02:00
родитель 36d87a17a8
Коммит ac13b70a89
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 61E03CBED7BC859E

Просмотреть файл

@ -62,10 +62,12 @@
static int run_command_varg(char **output, const char *command, va_list args) static int run_command_varg(char **output, const char *command, va_list args)
{ {
FILE *pipe; FILE *pipe;
char redirect_stderr[] = "%s 2>&1";
char command_buf[BUFSIZ]; char command_buf[BUFSIZ];
char buf[BUFSIZ]; char buf[BUFSIZ];
char *p; char *p;
int ret; int ret;
if(output) { if(output) {
*output = NULL; *output = NULL;
} }
@ -78,18 +80,22 @@ static int run_command_varg(char **output, const char *command, va_list args)
} }
/* Rewrite the command to redirect stderr to stdout to we can output it */ /* Rewrite the command to redirect stderr to stdout to we can output it */
if(strlen(command_buf) + 6 >= sizeof(command_buf)) { if(strlen(command_buf) + strlen(redirect_stderr) >= sizeof(buf)) {
fprintf(stderr, "Unable to rewrite command (%s)\n", command); fprintf(stderr, "Unable to rewrite command (%s)\n", command);
return -1; return -1;
} }
strncat(command_buf, " 2>&1", 6); ret = snprintf(buf, sizeof(buf), redirect_stderr, command_buf);
if(ret < 0 || ret >= BUFSIZ) {
fprintf(stderr, "Unable to rewrite command (%s)\n", command);
return -1;
}
fprintf(stdout, "Command: %s\n", command); fprintf(stdout, "Command: %s\n", command);
#ifdef WIN32 #ifdef WIN32
pipe = _popen(command_buf, "r"); pipe = _popen(buf, "r");
#else #else
pipe = popen(command_buf, "r"); pipe = popen(buf, "r");
#endif #endif
if(!pipe) { if(!pipe) {
fprintf(stderr, "Unable to execute command '%s'\n", command); fprintf(stderr, "Unable to execute command '%s'\n", command);