diff options
author | Andrea Claudi <aclaudi@redhat.com> | 2023-05-29 18:59:15 +0200 |
---|---|---|
committer | Stephen Hemminger <stephen@networkplumber.org> | 2023-05-30 12:24:32 -0700 |
commit | 995096d946cbe1b8b8198b93fa3fc67240f3dcb6 (patch) | |
tree | b6f672d1793c9554a66566e3cf2c2f52327d1d09 | |
parent | 33c3776b3ab652a231b36a5aa319874aebad3c59 (diff) | |
download | iproute2-995096d946cbe1b8b8198b93fa3fc67240f3dcb6.tar.gz |
ipstats: fix message reporting error
strerror() accepts any integer as arguments, but returns meaningful
error descriptions only for positive integers.
ipstats code uses strerror on a code path where either err is 0 or
-ENOMEM, thus resulting in a useless error message.
Fix this using errno and moving the error printing closer to the only
function populating it in this code path.
Fixes: df0b2c6d0098 ("ipstats: Add a shell of "show" command")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r-- | ip/ipstats.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/ip/ipstats.c b/ip/ipstats.c index dadded14c..3f94ff1eb 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -88,8 +88,11 @@ ipstats_stat_show_attrs_alloc_tb(struct ipstats_stat_show_attrs *attrs, return 0; attrs->tbs[group] = calloc(ifla_max + 1, sizeof(*attrs->tbs[group])); - if (attrs->tbs[group] == NULL) - return -ENOMEM; + if (attrs->tbs[group] == NULL) { + fprintf(stderr, "Error parsing netlink answer: %s\n", + strerror(errno)); + return -errno; + } if (group == 0) err = parse_rtattr(attrs->tbs[group], ifla_max, @@ -755,11 +758,8 @@ ipstats_process_ifsm(struct nlmsghdr *answer, } err = ipstats_stat_show_attrs_alloc_tb(&show_attrs, 0); - if (err != 0) { - fprintf(stderr, "Error parsing netlink answer: %s\n", - strerror(err)); + if (err) return err; - } dev = ll_index_to_name(show_attrs.ifsm->ifindex); |