]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Fix size_columns() invocation that passes a 32-bit quantity
authorPetr Machata <petrm@nvidia.com>
Tue, 28 Jun 2022 10:17:31 +0000 (12:17 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 5 Jul 2022 16:09:43 +0000 (09:09 -0700)
In print_stats64(), the last size_columns() invocation passes number of
carrier changes as one of the arguments. The value is decoded as a 32-bit
quantity, but size_columns() expects a 64-bit one. This is undefined
behavior.

The reason valgrind does not cite this is that the previous size_columns()
invocations prime the ABI area used for the value transfer. When these
other invocations are commented away, valgrind does complain that
"conditional jump or move depends on uninitialised value", as would be
expected.

Fixes: 49437375b6c1 ("ip: dynamically size columns when printing stats")
Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipaddress.c

index 5a3b1cae4079fdf070beec6bb79fbd5227622c26..a288341c2411735119a5ee6b5c65f5d4607f8279 100644 (file)
@@ -783,13 +783,15 @@ void print_stats64(FILE *fp, struct rtnl_link_stats64 *s,
                             s->tx_bytes, s->tx_packets, s->tx_errors,
                             s->tx_dropped, s->tx_carrier_errors,
                             s->collisions, s->tx_compressed);
-               if (show_stats > 1)
+               if (show_stats > 1) {
+                       uint64_t cc = carrier_changes ?
+                                     rta_getattr_u32(carrier_changes) : 0;
+
                        size_columns(cols, ARRAY_SIZE(cols), 0, 0,
                                     s->tx_aborted_errors, s->tx_fifo_errors,
                                     s->tx_window_errors,
-                                    s->tx_heartbeat_errors,
-                                    carrier_changes ?
-                                    rta_getattr_u32(carrier_changes) : 0);
+                                    s->tx_heartbeat_errors, cc);
+               }
 
                /* RX stats */
                fprintf(fp, "    RX: %*s %*s %*s %*s %*s %*s %*s%s",