[systemd-commits] 2 commits - src/libsystemd-daemon src/shared

Michal Schmidt michich at kemper.freedesktop.org
Tue Oct 30 02:32:01 PDT 2012


 src/libsystemd-daemon/sd-daemon.c |   28 ++++++++++++++++++----------
 src/shared/conf-parser.c          |    2 +-
 src/shared/util.c                 |    8 ++++----
 3 files changed, 23 insertions(+), 15 deletions(-)

New commits:
commit 50425d1614bfa47c9f124d87e6d936671970f8c5
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Tue Oct 30 10:30:44 2012 +0100

    libsystemd-daemon: fix style

diff --git a/src/libsystemd-daemon/sd-daemon.c b/src/libsystemd-daemon/sd-daemon.c
index 480db3b..4801d2c 100644
--- a/src/libsystemd-daemon/sd-daemon.c
+++ b/src/libsystemd-daemon/sd-daemon.c
@@ -75,7 +75,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
         char *p = NULL;
         unsigned long l;
 
-        if (!(e = getenv("LISTEN_PID"))) {
+        e = getenv("LISTEN_PID");
+        if (!e) {
                 r = 0;
                 goto finish;
         }
@@ -99,7 +100,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
                 goto finish;
         }
 
-        if (!(e = getenv("LISTEN_FDS"))) {
+        e = getenv("LISTEN_FDS");
+        if (!e) {
                 r = 0;
                 goto finish;
         }
@@ -120,7 +122,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
         for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
                 int flags;
 
-                if ((flags = fcntl(fd, F_GETFD)) < 0) {
+                flags = fcntl(fd, F_GETFD);
+                if (flags < 0) {
                         r = -errno;
                         goto finish;
                 }
@@ -270,7 +273,8 @@ _sd_export_ int sd_is_socket(int fd, int family, int type, int listening) {
         if (family < 0)
                 return -EINVAL;
 
-        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+        r = sd_is_socket_internal(fd, type, listening);
+        if (r <= 0)
                 return r;
 
         if (family > 0) {
@@ -300,7 +304,8 @@ _sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, u
         if (family != 0 && family != AF_INET && family != AF_INET6)
                 return -EINVAL;
 
-        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+        r = sd_is_socket_internal(fd, type, listening);
+        if (r <= 0)
                 return r;
 
         memset(&sockaddr, 0, sizeof(sockaddr));
@@ -342,7 +347,8 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *p
         socklen_t l;
         int r;
 
-        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+        r = sd_is_socket_internal(fd, type, listening);
+        if (r <= 0)
                 return r;
 
         memset(&sockaddr, 0, sizeof(sockaddr));
@@ -432,7 +438,8 @@ _sd_export_ int sd_notify(int unset_environment, const char *state) {
                 goto finish;
         }
 
-        if (!(e = getenv("NOTIFY_SOCKET")))
+        e = getenv("NOTIFY_SOCKET");
+        if (!e)
                 return 0;
 
         /* Must be an abstract socket, or an absolute path */
@@ -441,7 +448,8 @@ _sd_export_ int sd_notify(int unset_environment, const char *state) {
                 goto finish;
         }
 
-        if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
+        fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+        if (fd < 0) {
                 r = -errno;
                 goto finish;
         }

commit f3910003bce32ebdc1dbb71fd9ca2d4b8352b563
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Tue Oct 30 10:29:40 2012 +0100

    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

diff --git a/src/libsystemd-daemon/sd-daemon.c b/src/libsystemd-daemon/sd-daemon.c
index 863ac75..480db3b 100644
--- a/src/libsystemd-daemon/sd-daemon.c
+++ b/src/libsystemd-daemon/sd-daemon.c
@@ -88,7 +88,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
                 goto finish;
         }
 
-        if (!p || *p || l <= 0) {
+        if (!p || p == e || *p || l <= 0) {
                 r = -EINVAL;
                 goto finish;
         }
@@ -112,7 +112,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
                 goto finish;
         }
 
-        if (!p || *p) {
+        if (!p || p == e || *p) {
                 r = -EINVAL;
                 goto finish;
         }
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 4bf3147..9f5c07c 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -865,7 +865,7 @@ int config_parse_mode(
 
         errno = 0;
         l = strtol(rvalue, &x, 8);
-        if (!x || *x || errno) {
+        if (!x || x == rvalue || *x || errno) {
                 log_error("[%s:%u] Failed to parse mode value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
diff --git a/src/shared/util.c b/src/shared/util.c
index 8ec83e4..23832fe 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;



More information about the systemd-commits mailing list