[master] f3b172acd vav: Ditch sscanf() in favor of VNUM_hex()

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Aug 31 10:23:07 UTC 2021


commit f3b172acdfb9f0c9022714630f8228eecd6ec618
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Aug 31 11:59:03 2021 +0200

    vav: Ditch sscanf() in favor of VNUM_hex()
    
    With this vav_test needs to link against libm, but it's simpler to tell
    libvarnish to link since it's the one shipping VNUM in the first place.
    
    Fixes #3645

diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index 0559a77cc..d19e61409 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -44,7 +44,7 @@ libvarnish_la_SOURCES = \
 	vtim.c \
 	vus.c
 
-libvarnish_la_LIBADD = @PCRE2_LIBS@
+libvarnish_la_LIBADD = @PCRE2_LIBS@ $(LIBM)
 
 TESTS = vav_test vbh_test vct_test vjsn_test vnum_c_test vsb_test
 
@@ -64,7 +64,7 @@ vct_test_LDADD = $(AM_LDFLAGS) libvarnish.la
 
 vnum_c_test_SOURCES = vnum.c
 vnum_c_test_CFLAGS = $(AM_CFLAGS) -DNUM_C_TEST
-vnum_c_test_LDADD = $(AM_LDFLAGS) libvarnish.la ${LIBM}
+vnum_c_test_LDADD = $(AM_LDFLAGS) libvarnish.la
 
 vjsn_test_SOURCES = vjsn.c
 vjsn_test_CFLAGS = $(AM_CFLAGS) -DVJSN_TEST
diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c
index ffebc3f49..42ea2bca1 100644
--- a/lib/libvarnish/vav.c
+++ b/lib/libvarnish/vav.c
@@ -43,6 +43,7 @@
 #include "config.h"
 
 #include <ctype.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -51,13 +52,14 @@
 
 #include "vas.h"
 #include "vav.h"
+#include "vnum.h"
 
 static int
 vav_backslash_txt(const char *s, const char *e, char *res)
 {
-	int r, l;
+	int r, l, i;
+	const char *p;
 	char c;
-	unsigned u;
 
 	AN(s);
 	if (e == NULL)
@@ -102,10 +104,10 @@ vav_backslash_txt(const char *s, const char *e, char *res)
 		}
 		break;
 	case 'x':
-		if (l >= 4 && isxdigit(s[2]) && isxdigit(s[3]) &&
-		    sscanf(s + 1, "x%02x", &u) == 1) {
-			AZ(u & ~0xff);
-			c = u;	/*lint !e734 loss of precision */
+		if (l >= 4 && (i = VNUM_hex(s + 2, s + 4, &p)) >= 0 &&
+		    p == s + 4) {
+			AZ(i & ~0xff);
+			c = i;	/*lint !e734 loss of precision */
 			r = 4;
 		}
 		break;


More information about the varnish-commit mailing list