[systemd-commits] 4 commits - src/libsystemd-network src/network src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Jan 1 10:37:27 PST 2015


 src/libsystemd-network/sd-lldp.c |    2 +-
 src/network/networkctl.c         |   28 ++++++++++++++++------------
 src/shared/missing.h             |   24 ++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 13 deletions(-)

New commits:
commit ba52f15a5827b7ae8c55c53cdcc5bb9a6abbf0db
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Jan 1 12:00:59 2015 -0500

    networkctl: avoid potential use of unitialized variables
    
    Those values are based on a file we read from disk, so we should
    verify everything we receive, and make sure everything we print
    is sensible.
    
    Also, print fractional seconds for TTL.

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index f85058c..f7e300b 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -898,7 +898,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
         _cleanup_free_ LinkInfo *links = NULL;
         const char *state, *word;
 
-        usec_t time, until, ttl;
+        double ttl = -1;
         uint32_t capability;
         int i, r, c, j;
         size_t ll;
@@ -964,13 +964,19 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                                                 return -ENOMEM;
 
                                 } else if (streq(a, "_TTL")) {
+                                        long long unsigned x;
+                                        usec_t time;
 
-                                        time = now(CLOCK_BOOTTIME);
-
-                                        sscanf(b, USEC_FMT, &until);
+                                        r = safe_atollu(b, &x);
+                                        if (r < 0 || (usec_t) x != x)
+                                                return log_warning_errno(r < 0 ? r : ERANGE,
+                                                                         "Failed to parse TTL \"%s\": %m", b);
 
-                                        ttl = (until - time) / USEC_PER_SEC;
+                                        time = now(CLOCK_BOOTTIME);
+                                        if (x < time)
+                                                continue;
 
+                                        ttl = (double) (x - time) / USEC_PER_SEC;
 
                                 } else if (streq(a, "_CAP")) {
                                         sscanf(b, "%x", &capability);
@@ -980,8 +986,11 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
 
                         }
 
-                        if (until > time) {
-                                printf("%10s %24s %16s %16"PRIu64" %16s\n", links[i].name, chassis, port, ttl, cap);
+                        if (ttl >= 0) {
+                                printf("%10s %24s %16s %16f %16s\n",
+                                       links[i].name,
+                                       strna(chassis), strna(port),
+                                       ttl, cap);
                                 j++;
                         }
                 }

commit 1bf7dd6e7d36e997c7283045c2760d14e02904fd
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Jan 1 11:53:25 2015 -0500

    networkctl: remove unused variable

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index cc3ea85..f85058c 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -900,7 +900,6 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
 
         usec_t time, until, ttl;
         uint32_t capability;
-        char buf[LINE_MAX];
         int i, r, c, j;
         size_t ll;
         char **s;
@@ -955,15 +954,11 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                                         continue;
 
                                 if (streq(a, "_Chassis")) {
-
-                                        memzero(buf, LINE_MAX);
-
                                         chassis = strdup(b);
                                         if (!chassis)
                                                 return -ENOMEM;
 
                                 } else if (streq(a, "_Port")) {
-
                                         port = strdup(b);
                                         if (!port)
                                                 return -ENOMEM;

commit ef7532531942d59f81bfbd8a8f923f17e4827952
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Jan 1 11:15:50 2015 -0500

    network: fix scanf/printf format
    
    usec_t is defined as 64 bit wide, but long is 32 bit on many archs.

diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index fa45310..86c734b 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -495,7 +495,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
                         if (time - p->until <= 0)
                                 continue;
 
-                        sprintf(buf, "'_TTL=%lu' ", p->until);
+                        sprintf(buf, "'_TTL="USEC_FMT"' ", p->until);
 
                         k = strappend(s, buf);
                         if (!k)
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 15dfb81..cc3ea85 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -972,7 +972,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
 
                                         time = now(CLOCK_BOOTTIME);
 
-                                        sscanf(b, "%lu", &until);
+                                        sscanf(b, USEC_FMT, &until);
 
                                         ttl = (until - time) / USEC_PER_SEC;
 
@@ -986,7 +986,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                         }
 
                         if (until > time) {
-                                printf("%10s %24s %16s %16lu %16s\n", links[i].name, chassis, port, ttl, cap);
+                                printf("%10s %24s %16s %16"PRIu64" %16s\n", links[i].name, chassis, port, ttl, cap);
                                 j++;
                         }
                 }

commit e65ef51dee7a7d3565f471b67f29a257c6128fb3
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Jan 1 10:55:19 2015 -0500

    missing: add __NR_renameat2

diff --git a/src/shared/missing.h b/src/shared/missing.h
index 94d9d8d..5cf179e 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -679,6 +679,30 @@ static inline pid_t raw_getpid(void) {
 }
 
 #if !HAVE_DECL_RENAMEAT2
+
+#ifndef __NR_renameat2
+#  if defined __x86_64__
+#    define __NR_renameat2 316
+#  elif defined __arm__
+#    define __NR_renameat2 382
+#  elif defined _MIPS_SIM
+#    if _MIPS_SIM == _MIPS_SIM_ABI32
+#      define __NR_renameat2 4351
+#    endif
+#    if _MIPS_SIM == _MIPS_SIM_NABI32
+#      define __NR_renameat2 6315
+#    endif
+#    if _MIPS_SIM == _MIPS_SIM_ABI64
+#      define __NR_renameat2 5311
+#    endif
+#  elif defined __i386__
+#    define __NR_renameat2 353
+#  else
+#    warning "__NR_renameat2 unknown for your architecture"
+#    define __NR_renameat2 0xffffffff
+#  endif
+#endif
+
 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
         return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
 }



More information about the systemd-commits mailing list