Browse Source

Check argv for NULL in history

Serj Kalichev 10 years ago
parent
commit
f5f82efd6a
2 changed files with 12 additions and 3 deletions
  1. 9 2
      clish/shell/shell_execute.c
  2. 3 1
      lub/argv/argv__get_arg.c

+ 9 - 2
clish/shell/shell_execute.c

@@ -68,9 +68,13 @@ static int clish_source_internal(clish_context_t *context,
 	const lub_argv_t * argv, bool_t stop_on_error)
 {
 	int result = -1;
-	const char *filename = lub_argv__get_arg(argv, 0);
+	const char *filename = NULL;
 	struct stat fileStat;
 
+	if (!argv) /* Empty arguments */
+		return -1;
+	filename = lub_argv__get_arg(argv, 0);
+
 	/* the exception proves the rule... */
 	clish_shell_t *this = (clish_shell_t *)context->shell;
 
@@ -139,8 +143,11 @@ static int clish_history(clish_context_t *context, const lub_argv_t *argv,
 	tinyrl_history_iterator_t iter;
 	const tinyrl_history_entry_t *entry;
 	unsigned limit = 0;
-	const char *arg = lub_argv__get_arg(argv, 0);
+	const char *arg = NULL;
 
+	/* Get history limit */
+	if (argv)
+		arg = lub_argv__get_arg(argv, 0);
 	if (arg && ('\0' != *arg)) {
 		limit = (unsigned)atoi(arg);
 		if (0 == limit) {

+ 3 - 1
lub/argv/argv__get_arg.c

@@ -4,10 +4,12 @@
 #include "private.h"
 
 /*--------------------------------------------------------- */
-const char *lub_argv__get_arg(const lub_argv_t * this, unsigned index)
+const char *lub_argv__get_arg(const lub_argv_t *this, unsigned int index)
 {
 	const char *result = NULL;
 
+	if (!this)
+		return NULL;
 	if (this->argc > index)
 		result = this->argv[index].arg;