diff options
author | Mikhail Efremov <sem@altlinux.org> | 2019-03-29 19:48:17 +0300 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2019-03-31 13:15:54 +0100 |
commit | c3c04a9a1f590754cdd022a61fbde673e6660ce8 (patch) | |
tree | 32049676547c32c759a6399301dac00ce7bf484c | |
parent | f65b38b9317e1298cfc5877b0eed7c7badbe597a (diff) | |
download | iputils-c3c04a9a1f590754cdd022a61fbde673e6660ce8.tar.gz |
ping: fix use-after-free
Addresses: https://github.com/iputils/iputils/issues/171.
-rw-r--r-- | ping.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -543,19 +543,20 @@ int ping4_run(int argc, char **argv, struct addrinfo *ai, socket_st *sock) options |= F_NUMERIC; } else { struct addrinfo *result = NULL; + struct addrinfo *tmp_ai = ai; int ret_val; - if (argc > 1 || !ai) { + if (argc > 1 || !tmp_ai) { ret_val = getaddrinfo(target, NULL, &hints, &result); if (ret_val) error(2, 0, "%s: %s", target, gai_strerror(ret_val)); - ai = result; + tmp_ai = result; } - memcpy(&whereto, ai->ai_addr, sizeof whereto); + memcpy(&whereto, tmp_ai->ai_addr, sizeof whereto); memset(hnamebuf, 0, sizeof hnamebuf); - if (ai->ai_canonname) - strncpy(hnamebuf, ai->ai_canonname, sizeof hnamebuf - 1); + if (tmp_ai->ai_canonname) + strncpy(hnamebuf, tmp_ai->ai_canonname, sizeof hnamebuf - 1); hostname = hnamebuf; if (result) |