Mailing List Archive

[6.0] c89cc48ac vav: VAV_ParseTxt() to work without a null terminator
commit c89cc48aca3ed35a484a6463100319455758f2c2
Author: Dridi Boukelmoune <dridi.boukelmoune@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 a3861cf40..37d4af1c7 100644
--- a/include/vav.h
+++ b/include/vav.h
@@ -29,6 +29,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 f1bc3db10..e7150df0c 100644
--- a/lib/libvarnish/vav.c
+++ b/lib/libvarnish/vav.c
@@ -134,14 +134,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);
@@ -149,7 +152,7 @@ VAV_Parse(const char *s, int *argc, int flag)
return (NULL);

for (;;) {
- if (*s == '\0')
+ if (s >= e)
break;
if (isspace(*s)) {
s++;
@@ -175,7 +178,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;
@@ -184,7 +187,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);
}
@@ -203,7 +206,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;
@@ -212,6 +215,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)
{
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit