|
@@ -48,14 +48,20 @@ static struct command commands_end[0] __table_end ( commands );
|
48
|
48
|
*/
|
49
|
49
|
int execv ( const char *command, char * const argv[] ) {
|
50
|
50
|
struct command *cmd;
|
51
|
|
- int argc = 0;
|
52
|
|
-
|
53
|
|
- assert ( argv[0] != NULL );
|
|
51
|
+ int argc;
|
54
|
52
|
|
55
|
53
|
/* Count number of arguments */
|
56
|
|
- do {
|
57
|
|
- argc++;
|
58
|
|
- } while ( argv[argc] != NULL );
|
|
54
|
+ for ( argc = 0 ; argv[argc] ; argc++ ) {}
|
|
55
|
+
|
|
56
|
+ /* Sanity checks */
|
|
57
|
+ if ( ! command ) {
|
|
58
|
+ DBG ( "No command\n" );
|
|
59
|
+ return -EINVAL;
|
|
60
|
+ }
|
|
61
|
+ if ( ! argc ) {
|
|
62
|
+ DBG ( "%s: empty argument list\n", command );
|
|
63
|
+ return -EINVAL;
|
|
64
|
+ }
|
59
|
65
|
|
60
|
66
|
/* Reset getopt() library ready for use by the command. This
|
61
|
67
|
* is an artefact of the POSIX getopt() API within the context
|