]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Keep too-long lines from overwriting output_buffer (#5093)
authorJames Jones <jejones3141@gmail.com>
Fri, 28 Jul 2023 14:15:29 +0000 (09:15 -0500)
committerGitHub <noreply@github.com>
Fri, 28 Jul 2023 14:15:29 +0000 (10:15 -0400)
This came up because of CID #1533664, but almost certainly won't
placate coverity. It just makes sure that it won't ask for more
than will fit in output_buff, at the extremely rare cost of not
printing all of the remaining part of the line.

src/bin/unit_test_module.c

index 5122718ecf1a75c66d57a9ff343440a8291409b5..f1365c169754f0ea9696a7554c857688c3ce24e9 100644 (file)
@@ -418,8 +418,14 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp)
                        }
 
                        if (fr_sbuff_remaining(&line) > 0) {
+                               int err_len;
+                       too_much_text:
+                               err_len = strlen("ERROR offset " " 'Too much text' ::" "::") + 4 +
+                                         fr_sbuff_remaining(&line);
+                               if (err_len > (int) sizeof(output_buff) - 1) err_len = (int) sizeof(output_buff) - 1;
                                talloc_free(xlat_ctx);
-                               fr_sbuff_in_sprintf(&out,  "ERROR offset %d 'Too much text' ::%s::", (int) slen, fr_sbuff_current(&line));
+                               fr_sbuff_in_sprintf(&out, "ERROR offset %d 'Too much text' ::%.*s::",
+                                                   (int) slen, err_len, fr_sbuff_current(&line));
                                continue;
                        }
 
@@ -465,11 +471,7 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp)
                                continue;
                        }
 
-                       if (fr_sbuff_remaining(&line) > 0) {
-                               talloc_free(xlat_ctx);
-                               fr_sbuff_in_sprintf(&out, "ERROR offset %d 'Too much text' ::%s::", (int) slen, fr_sbuff_current(&line));
-                               continue;
-                       }
+                       if (fr_sbuff_remaining(&line) > 0) goto too_much_text;
 
                        if (xlat_resolve(head, NULL) < 0) {
                                talloc_free(xlat_ctx);