| 269 | */ |
| 270 | |
| 271 | int32_t exec_check |
| 272 | ( |
| 273 | string const * command, |
| 274 | LIST * * pShell, |
| 275 | int32_t * error_length, |
| 276 | int32_t * error_max_length |
| 277 | ) |
| 278 | { |
| 279 | /* Default shell does nothing when triggered with an empty or a |
| 280 | * whitespace-only command so we simply skip running it in that case. We |
| 281 | * still pass them on to non-default shells as we do not really know what |
| 282 | * they are going to do with such commands. |
| 283 | */ |
| 284 | if ( list_empty( *pShell ) ) |
| 285 | { |
| 286 | char const * s = command->value; |
| 287 | while ( isspace( *s ) ) ++s; |
| 288 | if ( !*s ) |
| 289 | return EXEC_CHECK_NOOP; |
| 290 | } |
| 291 | |
| 292 | /* Check prerequisites for executing raw commands. */ |
| 293 | if ( is_raw_command_request( *pShell ) ) |
| 294 | { |
| 295 | int32_t const raw_cmd_length = raw_command_length( command->value ); |
| 296 | if ( raw_cmd_length < 0 ) |
| 297 | { |
| 298 | /* Invalid characters detected - fallback to default shell. */ |
| 299 | list_free( *pShell ); |
| 300 | *pShell = L0; |
| 301 | } |
| 302 | else if ( raw_cmd_length > MAX_RAW_COMMAND_LENGTH ) |
| 303 | { |
| 304 | *error_length = raw_cmd_length; |
| 305 | *error_max_length = MAX_RAW_COMMAND_LENGTH; |
| 306 | return EXEC_CHECK_TOO_LONG; |
| 307 | } |
| 308 | else |
| 309 | return raw_cmd_length ? EXEC_CHECK_OK : EXEC_CHECK_NOOP; |
| 310 | } |
| 311 | |
| 312 | /* Now we know we are using an external shell. Note that there is no need to |
| 313 | * check for too long command strings when using an external shell since we |
| 314 | * use a command file and assume no one is going to set up a JAMSHELL format |
| 315 | * string longer than a few hundred bytes at most which should be well under |
| 316 | * the total command string limit. Should someone actually construct such a |
| 317 | * JAMSHELL value it will get reported as an 'invalid parameter' |
| 318 | * CreateProcessA() Windows API failure which seems like a good enough |
| 319 | * result for such intentional mischief. |
| 320 | */ |
| 321 | |
| 322 | /* Check for too long command lines. */ |
| 323 | return check_cmd_for_too_long_lines( command->value, shell_maxline(), |
| 324 | error_length, error_max_length ); |
| 325 | } |
| 326 | |
| 327 | |
| 328 | /* |
no test coverage detected