summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-10-30 10:29:40 +0100
committerMichal Schmidt <mschmidt@redhat.com>2012-10-30 10:30:04 +0100
commitf3910003bce32ebdc1dbb71fd9ca2d4b8352b563 (patch)
tree86d7662a2c26332b67add144ad20e63abdbd1aa1 /src/shared/util.c
parent0eb59ccfe619cbc4b42ef8ff02b52971994dfe05 (diff)
shared, libsystemd-daemon: check for empty strings in strto*l conversions
strtol() and friends may set EINVAL if no conversion was performed, but they are not required to do so. In practice they don't. We need to check for it. https://bugzilla.redhat.com/show_bug.cgi?id=870577
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 8ec83e49a8..23832fe16a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -377,7 +377,7 @@ int safe_atou(const char *s, unsigned *ret_u) {
errno = 0;
l = strtoul(s, &x, 0);
- if (!x || *x || errno)
+ if (!x || x == s || *x || errno)
return errno ? -errno : -EINVAL;
if ((unsigned long) (unsigned) l != l)
@@ -397,7 +397,7 @@ int safe_atoi(const char *s, int *ret_i) {
errno = 0;
l = strtol(s, &x, 0);
- if (!x || *x || errno)
+ if (!x || x == s || *x || errno)
return errno ? -errno : -EINVAL;
if ((long) (int) l != l)
@@ -417,7 +417,7 @@ int safe_atollu(const char *s, long long unsigned *ret_llu) {
errno = 0;
l = strtoull(s, &x, 0);
- if (!x || *x || errno)
+ if (!x || x == s || *x || errno)
return errno ? -errno : -EINVAL;
*ret_llu = l;
@@ -434,7 +434,7 @@ int safe_atolli(const char *s, long long int *ret_lli) {
errno = 0;
l = strtoll(s, &x, 0);
- if (!x || *x || errno)
+ if (!x || x == s || *x || errno)
return errno ? -errno : -EINVAL;
*ret_lli = l;