]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove needless checks from xlat_config_escape(). (#4536)
authorJames Jones <jejones3141@gmail.com>
Wed, 1 Jun 2022 01:22:37 +0000 (20:22 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 01:22:37 +0000 (21:22 -0400)
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.

src/lib/server/main_config.c

index 25687f410d3cc6837f8b1eca11e9477563c81644..da5f81fde197d11bc54395abb94ca5c1d5c33473 100644 (file)
@@ -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.
                 */