diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2016-03-26 10:58:49 +0000 |
---|---|---|
committer | Stefan Bühler <stbuehler@web.de> | 2016-03-26 10:58:49 +0000 |
commit | f5453290b7742443da98728cacfeeca42aafa7f6 (patch) | |
tree | e97e894ea446112d7d01afbc0f95d3cd2bcaf30e /src/configparser.y | |
parent | 733ce382030bdf4fe362b24da1ab7728aca8d11f (diff) | |
download | lighttpd-git-f5453290b7742443da98728cacfeeca42aafa7f6.tar.gz |
validate return values from strtol, strtoul (fixes #2564)
From: Glenn Strauss <gstrauss@gluelogic.com>
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3122 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/configparser.y')
-rw-r--r-- | src/configparser.y | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/configparser.y b/src/configparser.y index 56a4bf9b..12be92ad 100644 --- a/src/configparser.y +++ b/src/configparser.y @@ -9,6 +9,8 @@ #include "array.h" #include <assert.h> +#include <ctype.h> +#include <errno.h> #include <stdio.h> #include <string.h> @@ -267,8 +269,16 @@ value(A) ::= STRING(B). { } value(A) ::= INTEGER(B). { + char *endptr; A = (data_unset *)data_integer_init(); - ((data_integer *)(A))->value = strtol(B->ptr, NULL, 10); + errno = 0; + ((data_integer *)(A))->value = strtol(B->ptr, &endptr, 10); + /* skip trailing whitespace */ + if (endptr != B->ptr) while (isspace(*endptr)) endptr++; + if (0 != errno || *endptr != '\0') { + fprintf(stderr, "error parsing number: '%s'\n", B->ptr); + ctx->ok = 0; + } buffer_free(B); B = NULL; } |