diff options
author | Max Kellermann <max@duempel.org> | 2012-02-14 18:59:41 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-02-14 18:59:41 +0100 |
commit | 52e9cab1c1743f64a733f01ebaf67e3bd1530a93 (patch) | |
tree | 1544decbab56a1636e7946019c1d48240803e6c7 /src | |
parent | 1baaaa40cc1f0632320099f066474df942de9467 (diff) | |
download | mpd-52e9cab1c1743f64a733f01ebaf67e3bd1530a93.tar.gz mpd-52e9cab1c1743f64a733f01ebaf67e3bd1530a93.tar.xz mpd-52e9cab1c1743f64a733f01ebaf67e3bd1530a93.zip |
command: check for empty string after strtol()
An empty string is obviously not a valid integer.
Diffstat (limited to '')
-rw-r--r-- | src/command.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/command.c b/src/command.c index bcaea0181..b8f49e2e3 100644 --- a/src/command.c +++ b/src/command.c @@ -122,7 +122,7 @@ check_uint32(struct client *client, uint32_t *dst, char *test; *dst = strtoul(s, &test, 10); - if (*test != '\0') { + if (test == s || *test != '\0') { va_list args; va_start(args, fmt); command_error_v(client, ACK_ERROR_ARG, fmt, args); @@ -140,7 +140,7 @@ check_int(struct client *client, int *value_r, long value; value = strtol(s, &test, 10); - if (*test != '\0') { + if (test == s || *test != '\0') { va_list args; va_start(args, fmt); command_error_v(client, ACK_ERROR_ARG, fmt, args); @@ -168,7 +168,7 @@ check_range(struct client *client, unsigned *value_r1, unsigned *value_r2, long value; value = strtol(s, &test, 10); - if (*test != '\0' && *test != ':') { + if (test == s || (*test != '\0' && *test != ':')) { va_list args; va_start(args, fmt); command_error_v(client, ACK_ERROR_ARG, fmt, args); @@ -202,7 +202,7 @@ check_range(struct client *client, unsigned *value_r1, unsigned *value_r2, if (*test == ':') { value = strtol(++test, &test2, 10); - if (*test2 != '\0') { + if (test2 == test || *test2 != '\0') { va_list args; va_start(args, fmt); command_error_v(client, ACK_ERROR_ARG, fmt, args); @@ -241,7 +241,7 @@ check_unsigned(struct client *client, unsigned *value_r, const char *s) char *endptr; value = strtoul(s, &endptr, 10); - if (*endptr != 0) { + if (endptr == s || *endptr != 0) { command_error(client, ACK_ERROR_ARG, "Integer expected: %s", s); return false; @@ -264,7 +264,7 @@ check_bool(struct client *client, bool *value_r, const char *s) char *endptr; value = strtol(s, &endptr, 10); - if (*endptr != 0 || (value != 0 && value != 1)) { + if (endptr == s || *endptr != 0 || (value != 0 && value != 1)) { command_error(client, ACK_ERROR_ARG, "Boolean (0/1) expected: %s", s); return false; @@ -281,7 +281,7 @@ check_float(struct client *client, float *value_r, const char *s) char *endptr; value = strtof(s, &endptr); - if (*endptr != 0 && endptr == s) { + if (endptr == s || *endptr != 0) { command_error(client, ACK_ERROR_ARG, "Float expected: %s", s); return false; |