From 89fc6d6aa211d224ea29dfa586d0e5e64a25eca3 Mon Sep 17 00:00:00 2001 From: CodeforEvolution Date: Mon, 21 Oct 2019 10:27:38 -0500 Subject: [PATCH] [hey] - Fix overflow issue found by LGTM LGTM issue: "gets does not guard against buffer overflow" Change-Id: I502428f167865ac81301aa72d20c91b4480fb3dc Reviewed-on: https://review.haiku-os.org/c/haiku/+/1926 Reviewed-by: Adrien Destugues --- src/bin/hey.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/hey.cpp b/src/bin/hey.cpp index d736808a19..9c3d1b0c3a 100644 --- a/src/bin/hey.cpp +++ b/src/bin/hey.cpp @@ -126,6 +126,9 @@ bool is_valid_char(uint8 c); const char VERSION[] = "v1.2.8"; +#define MAX_INPUT_SIZE 1024 + // Maximum amount of input data that "hey" can process at a time + #define DEBUG_HEY 0 // 1: prints the script message to be sent to the target application, 0: prints only the reply @@ -338,10 +341,10 @@ HeyInterpreterThreadHook(void* arg) if (environment.HasMessenger("Target")) environment.FindMessenger("Target", &target); - char command[1024]; + char command[MAX_INPUT_SIZE]; status_t err; BMessage reply; - while (gets(command)) { + while (fgets(command, sizeof(command), stdin)) { reply.MakeEmpty(); err = Hey(&target, command, &reply); if (!err) {