summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@alpinelinux.org>2013-06-28 19:41:31 -0700
committerNathan Angelacos <nangel@alpinelinux.org>2013-06-28 19:41:31 -0700
commit748da159164b2c45c95f6c019a7ba36251cea933 (patch)
treeedea708d1183dcdae3b02e95ddffd3b1d3a97390
parentb1bed843f31c2d59303ebea5e14f36df55e78262 (diff)
downloadhaserl-748da159164b2c45c95f6c019a7ba36251cea933.tar.bz2
haserl-748da159164b2c45c95f6c019a7ba36251cea933.tar.xz
Fix segfault when the first parameter is a quoted string, or a null string
modified: ChangeLog modified: configure.ac modified: src/common.c
-rw-r--r--ChangeLog9
-rw-r--r--configure.ac2
-rw-r--r--src/common.c22
3 files changed, 22 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c9d86f..e8a632d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+<<<<<<< HEAD
+2013-27-06
+ 0.9.30
+ * The Mayhem Team of CMU found an undisclosed segfault when the first
+ command-line argument is '' or "" (null-quoted string). Chow Loon Jin
+ supplied a patch.
+
+=======
+>>>>>>> parent of 59442ac... modified: ChangeLog - Added note about moving to git.
2011-05-09
0.9.29
* Jan Rome reported an off-by one error in handling array input (formvar[])
diff --git a/configure.ac b/configure.ac
index 91404c3..7998afb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
# Process this file with autoconf to produce a configure script.
-AC_INIT([haserl],[0.9.29],[Nathan Angelacos - nangel@users.sourceforge.net],[haserl])
+AC_INIT([haserl],[0.9.30],[Nathan Angelacos - nangel@users.sourceforge.net],[haserl])
AM_INIT_AUTOMAKE([haserl],[$PACKAGE_VERSION])
# Checks for programs.
diff --git a/src/common.c b/src/common.c
index 319891d..168a682 100644
--- a/src/common.c
+++ b/src/common.c
@@ -78,13 +78,14 @@ argc_argv (char *instr, argv_t ** argv, char *commentstr)
len = strlen (instr);
pos = 0;
+ char quoted = 0;
while (pos < len)
{
- // printf ("%3d of %3d: %s\n", pos, len, instr);
+ // printf ("%3d of %3d: %s\n", pos, len, instr);
+
/* Comments are really, really special */
-
if ((state == WHITESPACE) && (strchr (commentstr, *instr)))
{
while ((*instr != '\n') && (*instr != '\0'))
@@ -105,11 +106,10 @@ argc_argv (char *instr, argv_t ** argv, char *commentstr)
{
quote = *instr;
state = TOKENSTART;
+ quoted = -1;
if (*(instr + 1) == quote)
{ /* special case for NULL quote */
- quote = '\0';
*instr = '\0';
- argv_array[arg_count].quoted = -1;
}
else
{
@@ -119,11 +119,9 @@ argc_argv (char *instr, argv_t ** argv, char *commentstr)
}
else
{ /* WORDSPACE, so quotes end or quotes within quotes */
-
/* Is it the same kind of quote? */
- if (*instr == quote)
+ if ( (*instr == quote) && quoted )
{
- argv_array[arg_count - 1].quoted = -1;
quote = '\0';
*instr = '\0';
state = WHITESPACE;
@@ -189,14 +187,17 @@ argc_argv (char *instr, argv_t ** argv, char *commentstr)
return (-1);
}
argv_array[arg_count - 1].string = instr;
- argv_array[arg_count].quoted = 0;
+ argv_array[arg_count - 1].quoted = quoted;
state = WORDSPACE;
+ quoted = 0;
}
instr++;
pos++;
}
+ if ( arg_count == 0 ) return (0);
+
argv_array[arg_count].string = NULL;
*argv = argv_array;
return (arg_count);
@@ -337,14 +338,15 @@ main ()
strcpy (string,
- "\\This\\ string will be '' \"separated into\" \"'\\\"'\" ' 15 ' elements.\n"
+ "\\This\\ string will be '' \"separated into\" \"'\\\"'\" ' 16 ' elements.\n"
"' including a multi-line\n"
"element' with a comment. # This should not be parsed\n"
";Nor should this\n" "The End.");
- printf ("%s\n", string);
argc = argc_argv (string, &argv, "#;");
+ printf ("%s\n", string);
+
for (count = 0; count < argc; count++)
{
printf ("%03d: [%s] ", count, argv[count].string, "");