47 lines
1.7 KiB
Diff
47 lines
1.7 KiB
Diff
From c9c82b4576f0b616793ffbdc815c02e2e4da1f5c Mon Sep 17 00:00:00 2001
|
|
From: Radoslav Kolev <radoslav.kolev@suse.com>
|
|
Date: Thu, 15 May 2025 17:56:52 +0300
|
|
Subject: [PATCH] ping: Fix ipv4 ttl value when using SOCK_DGRAM on big endian
|
|
systems
|
|
|
|
7e7ffff attempted to fix a GCC warning about strict aliasing (which
|
|
it seems may have been an erroneous one in the first place), but
|
|
caused the ttl value when pinging an ipv4 address using SOCK_DGRAM
|
|
on a big endian system (for ex. IBM S390) to always appear as 0.
|
|
|
|
Using memcpy() instead of directly casting the value should be the
|
|
safest option, fixing the issue and also avoiding the possibility
|
|
of unaligned access to the value returned by CMSG_DATA.
|
|
|
|
Fixes: 7e7ffff ("ping: Silence GCC warnings when building with -fstrict-aliasing")
|
|
Reviewed-by: Petr Vorel <pvorel@suse.cz>
|
|
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
|
|
Signed-off-by: Radoslav Kolev <radoslav.kolev@suse.com>
|
|
---
|
|
ping/ping.c | 5 ++---
|
|
1 file changed, 2 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/ping/ping.c b/ping/ping.c
|
|
index 0faa8704..63b943e0 100644
|
|
--- a/ping/ping.c
|
|
+++ b/ping/ping.c
|
|
@@ -1642,7 +1642,7 @@ int ping4_parse_reply(struct ping_rts *rts, struct socket_st *sock,
|
|
int csfailed;
|
|
struct cmsghdr *cmsgh;
|
|
int reply_ttl;
|
|
- uint8_t *opts, *tmp_ttl;
|
|
+ uint8_t *opts;
|
|
int olen;
|
|
int wrong_source = 0;
|
|
|
|
@@ -1670,8 +1670,7 @@ int ping4_parse_reply(struct ping_rts *rts, struct socket_st *sock,
|
|
if (cmsgh->cmsg_type == IP_TTL) {
|
|
if (cmsgh->cmsg_len < sizeof(int))
|
|
continue;
|
|
- tmp_ttl = (uint8_t *)CMSG_DATA(cmsgh);
|
|
- reply_ttl = (int)*tmp_ttl;
|
|
+ memcpy(&reply_ttl, CMSG_DATA(cmsgh), sizeof(reply_ttl));
|
|
} else if (cmsgh->cmsg_type == IP_RETOPTS) {
|
|
opts = (uint8_t *)CMSG_DATA(cmsgh);
|
|
olen = cmsgh->cmsg_len;
|