Browse Source

Fix possible null dereference

Serj Kalichev 10 years ago
parent
commit
79224cb48b
2 changed files with 10 additions and 7 deletions
  1. 7 6
      clish/shell/shell_parse.c
  2. 3 1
      clish/shell/shell_tinyrl.c

+ 7 - 6
clish/shell/shell_parse.c

@@ -95,22 +95,25 @@ clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
 		clish_param_t *cparam = NULL;
 		int is_switch = 0;
 
+		if (!param)
+			return CLISH_BAD_PARAM;
+
 		/* Use real arg or PARAM's default value as argument */
 		if (*idx < argc)
 			arg = lub_argv__get_arg(argv, *idx);
 
 		/* Is parameter in "switch" mode? */
-		if (param && (CLISH_PARAM_SWITCH == clish_param__get_mode(param)))
+		if (CLISH_PARAM_SWITCH == clish_param__get_mode(param))
 			is_switch = 1;
 
 		/* Check the 'test' conditions */
-		if (param && !line_test(param, context)) {
+		if (!line_test(param, context)) {
 			index++;
 			continue;
 		}
 
 		/* Add param for help and completion */
-		if (param && last && (*idx == need_index) &&
+		if (last && (*idx == need_index) &&
 			(NULL == clish_pargv_find_arg(pargv, clish_param__get_name(param)))) {
 			if (is_switch) {
 				unsigned rec_paramc = clish_param__get_param_count(param);
@@ -149,7 +152,7 @@ clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
 		}
 
 		/* Set parameter value */
-		if (param) {
+		{
 			char *validated = NULL;
 			clish_paramv_t *rec_paramv =
 			    clish_param__get_paramv(param);
@@ -247,8 +250,6 @@ clish_pargv_status_t clish_shell_parse_pargv(clish_pargv_t *pargv,
 						return CLISH_BAD_PARAM;
 				}
 			}
-		} else {
-			return CLISH_BAD_PARAM;
 		}
 	}
 

+ 3 - 1
clish/shell/shell_tinyrl.c

@@ -74,10 +74,10 @@ static bool_t clish_shell_tinyrl_key_help(tinyrl_t * this, int key)
 static clish_pargv_status_t clish_shell_tinyrl_expand(tinyrl_t * this)
 {
 	clish_pargv_status_t status = CLISH_LINE_OK;
+#if 0
 	int rtn;
 	char *buffer;
 
-	return status;
 	/* first of all perform any history substitutions */
 	rtn = tinyrl_history_expand(tinyrl__get_history(this),
 		tinyrl__get_line(this), &buffer);
@@ -105,6 +105,8 @@ static clish_pargv_status_t clish_shell_tinyrl_expand(tinyrl_t * this)
 	}
 	free(buffer);
 
+#endif
+	this = this;
 	return status;
 }