aboutsummaryrefslogtreecommitdiff
path: root/sbin/route
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2021-02-07 17:21:18 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2021-02-08 21:42:20 +0000
commit4a01b854ca5c2e5124958363b3326708b913af71 (patch)
tree466705011527e1d00e89597d5d3b60854ca7d8c3 /sbin/route
parentd8c6d4c7321d4c969216bda8f792b45ed00afd64 (diff)
downloadsrc-4a01b854ca5c2e5124958363b3326708b913af71.tar.gz
src-4a01b854ca5c2e5124958363b3326708b913af71.zip
SO_RERROR indicates that receive buffer overflows should be handled as errors.
Historically receive buffer overflows have been ignored and programs could not tell if they missed messages or messages had been truncated because of overflows. Since programs historically do not expect to get receive overflow errors, this behavior is not the default. This is really really important for programs that use route(4) to keep in sync with the system. If we loose a message then we need to reload the full system state, otherwise the behaviour from that point is undefined and can lead to chasing bogus bug reports.
Diffstat (limited to 'sbin/route')
-rw-r--r--sbin/route/route.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 51a0c68746a6..b16fb6d17a08 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1444,9 +1444,20 @@ monitor(int argc, char *argv[])
interfaces();
exit(0);
}
+
+#ifdef SO_RERROR
+ n = 1;
+ if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1)
+ warn("SO_RERROR");
+#endif
+
for (;;) {
time_t now;
- n = read(s, msg, 2048);
+ n = read(s, msg, sizeof(msg));
+ if (n == -1) {
+ warn("read");
+ continue;
+ }
now = time(NULL);
(void)printf("\ngot message of size %d on %s", n, ctime(&now));
print_rtmsg((struct rt_msghdr *)(void *)msg, n);