From 6d8cd8a9a011901859071326fedd6da60b9bc2f5 Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Mon, 13 Mar 2023 12:44:57 +0300 Subject: [PATCH] Validate input string length --- src/backend/distributed/utils/attribute.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/utils/attribute.c b/src/backend/distributed/utils/attribute.c index 4674b800e..593e503d9 100644 --- a/src/backend/distributed/utils/attribute.c +++ b/src/backend/distributed/utils/attribute.c @@ -676,8 +676,13 @@ MultiTenantMonitorshmemSize(void) static char * extractTopComment(const char *inputString) { - int i = 0; + int commentStartCharsLength = 2; + if (strlen(inputString) < commentStartCharsLength ) + { + return NULL; + } + int i = 0; /* If query starts with a comment */ if (inputString[i] == '/' && inputString[i + 1] == '*') { @@ -689,9 +694,9 @@ extractTopComment(const char *inputString) } } - if (i > 2) + if (i > commentStartCharsLength) { - return get_substring(inputString, 2, i); + return get_substring(inputString, commentStartCharsLength, i); } else {