浏览代码

Cope with system("").

tags/v0.9.3
Michael Brown 18 年前
父节点
当前提交
0a26cd2933
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12
    6
      src/core/exec.c

+ 12
- 6
src/core/exec.c 查看文件

48
  */
48
  */
49
 int execv ( const char *command, char * const argv[] ) {
49
 int execv ( const char *command, char * const argv[] ) {
50
 	struct command *cmd;
50
 	struct command *cmd;
51
-	int argc = 0;
52
-
53
-	assert ( argv[0] != NULL );
51
+	int argc;
54
 
52
 
55
 	/* Count number of arguments */
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
 	/* Reset getopt() library ready for use by the command.  This
66
 	/* Reset getopt() library ready for use by the command.  This
61
 	 * is an artefact of the POSIX getopt() API within the context
67
 	 * is an artefact of the POSIX getopt() API within the context

正在加载...
取消
保存