Skip to contentSkip to conversation

server/server.c: don't deref NULL on failed strdup

PATCH In review Jim Meyering 1 participant 1 message Sep 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 server/server.c: don't deref NULL on failed strdup

This first one is so small it barely deserved a commit. The second fixes a bug.

From 8e6255aa5cddd7bd58d7e4dbd2ecc81f84c51ea2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 23 Sep 2010 10:47:22 +0200
Subject: [PATCH tabled 1/2] server/server.c: use "sizeof s" rather than equivalent "64"

---
 server/server.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
server/server.c +1 -1
index 3398026..a1af4f0 100644
@@ -356,7 +356,7 @@ static int authcheck(struct http_req *req, char *extra_bucket,
 		if (rc != DB_NOTFOUND) {
 			char s[64];
 
-			snprintf(s, 64, "get user '%s'", user);
+			snprintf(s, sizeof s, "get user '%s'", user);
 			tdbrep.tdb.passwd->err(tdbrep.tdb.passwd, rc, s);
 		}
 	} else {

--
1.7.3.234.g7bba3

From cf1f535adee9d93769cac5754c108ea9dac8a5c2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 23 Sep 2010 10:56:01 +0200
Subject: [PATCH tabled 2/2] server/server.c: don't deref NULL on failed strdup

Otherwise, hreq_sign(..., ..., NULL,...) would end up calling strlen(NULL).

---
 server/server.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
server/server.c +4 -0
index a1af4f0..87681a9 100644
@@ -363,6 +363,10 @@ static int authcheck(struct http_req *req, char *extra_bucket,
 		pass = val.data;
 	}
 
+	if (!pass) {
+		goto err_cmp;
+	}
+
 	hreq_sign(req, extra_bucket, pass, b64sig);
 	free(pass);
 

--
1.7.3.234.g7bba3