From: James Jones Date: Wed, 1 Jun 2022 01:22:37 +0000 (-0500) Subject: Remove needless checks from xlat_config_escape(). (#4536) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fed9d7291b18a159ba48762785b58d5432542a3;p=thirdparty%2Ffreeradius-server.git Remove needless checks from xlat_config_escape(). (#4536) The VLA escaped[] is declared to be large enough to hold the text from the value box even if every single character needs the largest possible encoding (MIME, which takes three characters to encode one). The bound checks will therefore never cause an error return. --- diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 25687f410d3..da5f81fde19 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -459,28 +459,18 @@ static int xlat_config_escape(UNUSED request_t *request, fr_value_box_t *vb, UNU * mime-encoded equivalents. */ if ((in[0] < 32)) { - if (outlen >= (outmax - 3)) return -1; - snprintf(out, outlen, "=%02X", (unsigned char) in[0]); out += 3; outlen += 3; continue; - - } else if (strchr(disallowed, *in) != NULL) { - if (outlen >= (outmax - 2)) return -1; - + } + if (strchr(disallowed, *in) != NULL) { out[0] = '\\'; out[1] = *in; out += 2; outlen += 2; continue; } - - /* - * Only one byte left. - */ - if (outlen >= (outmax - 1)) return -1; - /* * Allowed character. */