diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-01-01 12:00:59 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-01-01 13:36:44 -0500 |
commit | ba52f15a5827b7ae8c55c53cdcc5bb9a6abbf0db (patch) | |
tree | cb1a567b688ced21c31ce8eb8fa5a21f8481fd67 /src | |
parent | 1bf7dd6e7d36e997c7283045c2760d14e02904fd (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkctl.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index f85058c272..f7e300b442 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++; } } |