From 5c123faf5dd595e802152d12295667d2b6077277 Mon Sep 17 00:00:00 2001 From: Otto Date: Mon, 8 Nov 2021 14:10:31 +0100 Subject: [PATCH] Use sysconf if needed to get ARG_MAX --- pdns/rec_channel.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc index b87e551fb2..7cc46b8beb 100644 --- a/pdns/rec_channel.cc +++ b/pdns/rec_channel.cc @@ -165,6 +165,22 @@ static void waitForRead(int fd, unsigned int timeout, time_t start) } } +static size_t getArgMax() +{ +#if defined(ARG_MAX) + return ARG_MAX; +#endif + +#if defined(_SC_ARG_MAX) + auto tmp = sysconf(_SC_ARG_MAX); + if (tmp != -1) { + return tmp; + } +#endif + /* _POSIX_ARG_MAX */ + return 4096; +} + RecursorControlChannel::Answer RecursorControlChannel::recv(int fd, unsigned int timeout) { // timeout covers the operation of all read ops combined @@ -182,7 +198,7 @@ RecursorControlChannel::Answer RecursorControlChannel::recv(int fd, unsigned int throw PDNSException("Unable to receive length over control channel: " + stringerror()); } - if (len > ARG_MAX) { + if (len > getArgMax()) { throw PDNSException("Length of control channel message too large"); } -- 2.47.2