| 204 | */ |
| 205 | |
| 206 | int exec_check |
| 207 | ( |
| 208 | string const * command, |
| 209 | LIST * * pShell, |
| 210 | int * error_length, |
| 211 | int * error_max_length |
| 212 | ) |
| 213 | { |
| 214 | /* Default shell does nothing when triggered with an empty or a |
| 215 | * whitespace-only command so we simply skip running it in that case. We |
| 216 | * still pass them on to non-default shells as we do not really know what |
| 217 | * they are going to do with such commands. |
| 218 | */ |
| 219 | if ( list_empty( *pShell ) ) |
| 220 | { |
| 221 | char const * s = command->value; |
| 222 | while ( isspace( *s ) ) ++s; |
| 223 | if ( !*s ) |
| 224 | return EXEC_CHECK_NOOP; |
| 225 | } |
| 226 | |
| 227 | /* Check prerequisites for executing raw commands. */ |
| 228 | if ( is_raw_command_request( *pShell ) ) |
| 229 | { |
| 230 | int const raw_cmd_length = raw_command_length( command->value ); |
| 231 | if ( raw_cmd_length < 0 ) |
| 232 | { |
| 233 | /* Invalid characters detected - fallback to default shell. */ |
| 234 | list_free( *pShell ); |
| 235 | *pShell = L0; |
| 236 | } |
| 237 | else if ( raw_cmd_length > MAX_RAW_COMMAND_LENGTH ) |
| 238 | { |
| 239 | *error_length = raw_cmd_length; |
| 240 | *error_max_length = MAX_RAW_COMMAND_LENGTH; |
| 241 | return EXEC_CHECK_TOO_LONG; |
| 242 | } |
| 243 | else |
| 244 | return raw_cmd_length ? EXEC_CHECK_OK : EXEC_CHECK_NOOP; |
| 245 | } |
| 246 | |
| 247 | /* Now we know we are using an external shell. Note that there is no need to |
| 248 | * check for too long command strings when using an external shell since we |
| 249 | * use a command file and assume no one is going to set up a JAMSHELL format |
| 250 | * string longer than a few hundred bytes at most which should be well under |
| 251 | * the total command string limit. Should someone actually construct such a |
| 252 | * JAMSHELL value it will get reported as an 'invalid parameter' |
| 253 | * CreateProcessA() Windows API failure which seems like a good enough |
| 254 | * result for such intentional mischief. |
| 255 | */ |
| 256 | |
| 257 | /* Check for too long command lines. */ |
| 258 | return check_cmd_for_too_long_lines( command->value, maxline(), |
| 259 | error_length, error_max_length ); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /* |
no test coverage detected