[master] 114062dea vav: VAV_ParseTxt() to work without a null terminator
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Jun 17 12:35:06 UTC 2021
commit 114062dea9e895b1ef2136e6cae8c60f042c523a
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Jun 17 11:51:21 2021 +0200
vav: VAV_ParseTxt() to work without a null terminator
I kept a variable called "s" to cut noise from the diff.
diff --git a/include/vav.h b/include/vav.h
index c94cee902..9e0208f57 100644
--- a/include/vav.h
+++ b/include/vav.h
@@ -31,6 +31,7 @@
*/
void VAV_Free(char **argv);
+char **VAV_ParseTxt(const char *b, const char *e, int *argc, int flag);
char **VAV_Parse(const char *s, int *argc, int flag);
char *VAV_BackSlashDecode(const char *s, const char *e);
int VAV_BackSlash(const char *s, char *res);
diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c
index 611ae4ba8..de944032c 100644
--- a/lib/libvarnish/vav.c
+++ b/lib/libvarnish/vav.c
@@ -138,14 +138,17 @@ static char err_invalid_backslash[] = "Invalid backslash sequence";
static char err_missing_quote[] = "Missing '\"'";
char **
-VAV_Parse(const char *s, int *argc, int flag)
+VAV_ParseTxt(const char *b, const char *e, int *argc, int flag)
{
char **argv;
- const char *p;
+ const char *s, *p;
int nargv, largv;
int i, quote;
- assert(s != NULL);
+ AN(b);
+ if (e == NULL)
+ e = strchr(b, '\0');
+ s = b;
nargv = 1;
largv = 16;
argv = calloc(largv, sizeof *argv);
@@ -153,7 +156,7 @@ VAV_Parse(const char *s, int *argc, int flag)
return (NULL);
for (;;) {
- if (*s == '\0')
+ if (s >= e)
break;
if (isspace(*s)) {
s++;
@@ -179,7 +182,7 @@ VAV_Parse(const char *s, int *argc, int flag)
continue;
}
if (!quote) {
- if (*s == '\0' || isspace(*s))
+ if (s >= e || isspace(*s))
break;
if ((flag & ARGV_COMMA) && *s == ',')
break;
@@ -188,7 +191,7 @@ VAV_Parse(const char *s, int *argc, int flag)
}
if (*s == '"' && !(flag & ARGV_NOESC))
break;
- if (*s == '\0') {
+ if (s >= e) {
argv[0] = err_missing_quote;
return (argv);
}
@@ -207,7 +210,7 @@ VAV_Parse(const char *s, int *argc, int flag)
} else {
argv[nargv++] = VAV_BackSlashDecode(p, s);
}
- if (*s != '\0')
+ if (s < e)
s++;
}
argv[nargv] = NULL;
@@ -216,6 +219,13 @@ VAV_Parse(const char *s, int *argc, int flag)
return (argv);
}
+char **
+VAV_Parse(const char *s, int *argc, int flag)
+{
+
+ return (VAV_ParseTxt(s, NULL, argc, flag));
+}
+
void
VAV_Free(char **argv)
{
More information about the varnish-commit
mailing list