List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] cgit: use strtol_i instead of atoi
@ 2015-05-13 13:21 ncopa
  2015-05-13 13:35 ` Jason
  0 siblings, 1 reply; 7+ messages in thread
From: ncopa @ 2015-05-13 13:21 UTC (permalink / raw)


The use of atoi triggers a false positive in nessus security scanner who
believes it is an SQL injection.

Make nessus users happy by making the integer conversion slightly more
strict.

Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
---
 cgit.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/cgit.c b/cgit.c
index ae413c6..fccde9e 100644
--- a/cgit.c
+++ b/cgit.c
@@ -307,7 +307,7 @@ static void querystring_cb(const char *name, const char *value)
 		ctx.qry.sha2 = xstrdup(value);
 		ctx.qry.has_sha1 = 1;
 	} else if (!strcmp(name, "ofs")) {
-		ctx.qry.ofs = atoi(value);
+		strtol_i(value, 10, &ctx.qry.ofs);
 	} else if (!strcmp(name, "path")) {
 		ctx.qry.path = trim_end(value, '/');
 	} else if (!strcmp(name, "name")) {
@@ -317,22 +317,26 @@ static void querystring_cb(const char *name, const char *value)
 	} else if (!strcmp(name, "s")) {
 		ctx.qry.sort = xstrdup(value);
 	} else if (!strcmp(name, "showmsg")) {
-		ctx.qry.showmsg = atoi(value);
+		strtol_i(value, 10, &ctx.qry.showmsg);
 	} else if (!strcmp(name, "period")) {
 		ctx.qry.period = xstrdup(value);
 	} else if (!strcmp(name, "dt")) {
-		ctx.qry.difftype = atoi(value);
+		int difftype = 0;
+		strtol_i(value, 10, &difftype);
+		ctx.qry.difftype = difftype;
 		ctx.qry.has_difftype = 1;
 	} else if (!strcmp(name, "ss")) {
 		/* No longer generated, but there may be links out there. */
-		ctx.qry.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
+		int n = 0;
+		strtol_i(value, 10, &n);
+		ctx.qry.difftype = n ? DIFF_SSDIFF : DIFF_UNIFIED;
 		ctx.qry.has_difftype = 1;
 	} else if (!strcmp(name, "all")) {
-		ctx.qry.show_all = atoi(value);
+		strtol_i(value, 10, &ctx.qry.show_all);
 	} else if (!strcmp(name, "context")) {
-		ctx.qry.context = atoi(value);
+		strtol_i(value, 10, &ctx.qry.context);
 	} else if (!strcmp(name, "ignorews")) {
-		ctx.qry.ignorews = atoi(value);
+		strtol_i(value, 10, &ctx.qry.ignorews);
 	}
 }
 
-- 
2.4.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-05-15  7:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 13:21 [PATCH] cgit: use strtol_i instead of atoi ncopa
2015-05-13 13:35 ` Jason
2015-05-13 13:41   ` john
2015-05-13 13:45     ` john
2015-05-13 14:57       ` jamie.couture
2015-05-15  7:11         ` ncopa
2015-05-15  6:58       ` ncopa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).