cmd buffer overflow test simplified

issue406^2
Tim V. Shaporev 2014-02-03 22:58:03 +04:00
parent 74c5094cb0
commit 8e7902867d
1 changed files with 4 additions and 6 deletions

View File

@ -64,16 +64,14 @@ int main( int argc, char * argv[] )
if (quote) cmd[n++] = '"';
while (*s) { // copy & check
if ('"' == *s) cmd[n++] = *s; // duplicate it
if (n >= MAXCMDLEN-sizeof(redirect_str)) goto term;
cmd[n++] = *s++;
if (n >= MAXCMDLEN-sizeof(redirect_str)) {
fprintf(stderr, "Command line length exceeds limit of %d\n", MAXCMDLEN);
return 1;
}
}
if (quote) cmd[n++] = '"';
}
term:
if (n >= MAXCMDLEN-sizeof(redirect_str)) {
fprintf(stderr, "Command line length exceeds limit of %d\n", MAXCMDLEN);
return 1;
}
memcpy(&cmd[n], redirect_str, sizeof(redirect_str)); // including \0
cmd_stdout = _popen( cmd, "rt" );