]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_help: handle longer lines, exit on too long
authorDaniel Stenberg <daniel@haxx.se>
Tue, 6 Aug 2024 14:58:39 +0000 (16:58 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 6 Aug 2024 22:31:07 +0000 (00:31 +0200)
Follow-up to 9a0cf56471c1a

- increase the buffer to handle 160 characters manpage lines
- add another assert
- if the line buffer gets full, abort

Ideally, we add another step in the build process that makes the build
fail if this long lines are used.

Closes #14422

src/tool_help.c
src/tool_help.h

index b4dce29904332f5e790d85affe7d7d0257fd00b8..3e21efd7a7d9fbb9956a9fe260319dcaccbabe0b 100644 (file)
@@ -213,12 +213,18 @@ bool helpscan(unsigned char *buf, size_t len, struct scan_ctx *ctx)
 
     if(buf[i] == '\n') {
       DEBUGASSERT(ctx->olen < sizeof(ctx->obuf));
+      if(ctx->olen == sizeof(ctx->obuf))
+        return FALSE; /* bail out */
       ctx->obuf[ctx->olen++] = 0;
       ctx->olen = 0;
       puts(ctx->obuf);
     }
-    else
+    else {
+      DEBUGASSERT(ctx->olen < sizeof(ctx->obuf));
+      if(ctx->olen == sizeof(ctx->obuf))
+        return FALSE; /* bail out */
       ctx->obuf[ctx->olen++] = buf[i];
+    }
   }
   return TRUE;
 }
index 0a334464d2479074c56e58b03d21be78e605adca..4b40715375fba4a77c9fa55257209902ce0899c4 100644 (file)
@@ -37,7 +37,7 @@ struct scan_ctx {
   size_t elen;
   size_t olen;
   char rbuf[40];
-  char obuf[80];
+  char obuf[160];
   unsigned char show; /* start as at 0.
                          trigger match moves it to 1
                          arg match moves it to 2