From 7e5ac7c58a7a301d9c6d65bbc2c3632fc0fba5ed Mon Sep 17 00:00:00 2001
From: Mukund Sivaraman <muks@banu.com>
Date: Mon, 14 Jul 2008 17:13:06 +0530
Subject: Fix a regression where empty error variables caused strlen() to crash

This fixes a regression (bug #16) introduced in
95c1f39f6039dc82346f3e024e86a23b7103a0a6, where a NULL check was
removed. This caused NULL error variable values to be sent to
add_error_variable() in which strlen() segfaulted.

With this fix, custom stats pages should be displayed properly.

X-Banu-Bugzilla-Ids: 16
---
 src/html-error.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/html-error.c b/src/html-error.c
index c6b580e..1802cde 100644
--- a/src/html-error.c
+++ b/src/html-error.c
@@ -244,7 +244,9 @@ add_error_variable(struct conn_s *connptr, char *key, char *val)
 }
 
 #define ADD_VAR_RET(x, y)				   \
-	do {						   \
+	do {                                               \
+                if (y == NULL)                             \
+                        break;                             \
 		if (add_error_variable(connptr, x, y) < 0) \
 			return -1;			   \
 	} while (0)
@@ -266,14 +268,20 @@ add_standard_vars(struct conn_s *connptr)
         ADD_VAR_RET("request", connptr->request_line);
         ADD_VAR_RET("clientip", connptr->client_ip_addr);
         ADD_VAR_RET("clienthost", connptr->client_string_addr);
-        ADD_VAR_RET("version", VERSION);
-        ADD_VAR_RET("package", PACKAGE);
-        ADD_VAR_RET("website", "http://tinyproxy.banu.com/");
+
+        /* The following value parts are all non-NULL and will
+         * trigger warnings in ADD_VAR_RET(), so we use
+         * add_error_variable() directly.
+         */
 
         global_time = time(NULL);
         strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT",
                  gmtime(&global_time));
-        ADD_VAR_RET("date", timebuf);
+        add_error_variable(connptr, "date", timebuf);
+
+        add_error_variable(connptr, "website", "http://tinyproxy.banu.com/");
+        add_error_variable(connptr, "version", VERSION);
+        add_error_variable(connptr, "package", PACKAGE);
 
         return (0);
 }
-- 
cgit v1.2.3