]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
util: avoid calling snprintf in PrintStringsToBuffer
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 7 Oct 2021 12:30:56 +0000 (14:30 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 11 Oct 2021 06:35:40 +0000 (08:35 +0200)
As we print only one character

src/util-print.c

index fadd4e2fbfba985e979c7256654db42ce4bfb3c8..1f772a267da4290ccc17d427a72c18ee24dcb80f 100644 (file)
@@ -229,12 +229,13 @@ void PrintStringsToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32
                           const uint8_t *src_buf, const uint32_t src_buf_len)
 {
     uint32_t ch = 0;
-    for (ch = 0; ch < src_buf_len; ch++) {
-        PrintBufferData((char *)dst_buf, dst_buf_offset_ptr, dst_buf_size,
-                        "%c",
-                        (isprint((uint8_t)src_buf[ch]) ||
-                        src_buf[ch] == '\n' ||
-                        src_buf[ch] == '\r') ? (uint8_t)src_buf[ch] : '.');
+    for (ch = 0; ch < src_buf_len && *dst_buf_offset_ptr < dst_buf_size;
+            ch++, (*dst_buf_offset_ptr)++) {
+        if (isprint((uint8_t)src_buf[ch]) || src_buf[ch] == '\n' || src_buf[ch] == '\r') {
+            dst_buf[*dst_buf_offset_ptr] = src_buf[ch];
+        } else {
+            dst_buf[*dst_buf_offset_ptr] = '.';
+        }
     }
     dst_buf[dst_buf_size - 1] = 0;