aboutsummaryrefslogtreecommitdiffstats
path: root/sbin/ping
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2019-09-11 18:54:45 +0000
committerAlan Somers <asomers@FreeBSD.org>2019-09-11 18:54:45 +0000
commitb17fb99228587984f51ed7935ce659c078e39239 (patch)
tree8b246737767103760c3f69523830bdb743f7ca46 /sbin/ping
parentd2e6258258cf2492d36cf1d359e6c87e68180f28 (diff)
downloadsrc-b17fb99228587984f51ed7935ce659c078e39239.tar.gz
src-b17fb99228587984f51ed7935ce659c078e39239.zip
ping: Verify whether a datagram timestamp was actually received.
ping(8) uses SO_TIMESTAMP, which attaches a timestamp to each IP datagram at the time it's received by the kernel. Except that occasionally it doesn't. Add a check to see whether such a timestamp was actually set before trying to read it. This fixes segfaults that can happen when the kernel doesn't attach a timestamp. The bug has always existed, but prior to r351461 it manifested as an implausible round-trip-time, not a segfault. Reported by: pho MFC after: 3 days MFC-With: 351461
Notes
Notes: svn path=/head/; revision=352229
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/ping.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index a5ab70fd70c6..ebe97fb8e03a 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -931,7 +931,8 @@ main(int argc, char *const *argv)
continue;
}
#ifdef SO_TIMESTAMP
- if (cmsg->cmsg_level == SOL_SOCKET &&
+ if (cmsg != NULL &&
+ cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_TIMESTAMP &&
cmsg->cmsg_len == CMSG_LEN(sizeof *tv)) {
/* Copy to avoid alignment problems: */