From: Otto Date: Mon, 8 Nov 2021 13:10:31 +0000 (+0100) Subject: Use sysconf if needed to get ARG_MAX X-Git-Tag: rec-4.6.0-beta1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10965%2Fhead;p=thirdparty%2Fpdns.git Use sysconf if needed to get ARG_MAX --- 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"); }