1
0
Pārlūkot izejas kodu

Fix possible null dereference

Serj Kalichev 10 gadi atpakaļ
vecāks
revīzija
b279b70103
2 mainītis faili ar 10 papildinājumiem un 7 dzēšanām
  1. 7 6
      clish/shell/shell_parse.c
  2. 3 1
      clish/shell/shell_tinyrl.c

+ 7 - 6
clish/shell/shell_parse.c

@@ -96,22 +96,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);
@@ -150,7 +153,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);
@@ -248,8 +251,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

@@ -73,10 +73,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);
@@ -104,6 +104,8 @@ static clish_pargv_status_t clish_shell_tinyrl_expand(tinyrl_t *this)
 	}
 	free(buffer);
 
+#endif
+	this = this;
 	return status;
 }