Browse Source

HPCC-12047 String repad causes seg fault on -ve lengths

Additional check for invalid parameter

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 years ago
parent
commit
8453b0ec34
1 changed files with 2 additions and 0 deletions
  1. 2 0
      plugins/stringlib/stringlib.cpp

+ 2 - 0
plugins/stringlib/stringlib.cpp

@@ -1005,6 +1005,8 @@ STRINGLIB_API void STRINGLIB_CALL slStringRepeat(unsigned & tgtLen, char * & tgt
     else
     {
         tgtLen = srcLen*n;
+        if (tgtLen/n != srcLen) // Check did not overflow
+            rtlFail(0, "Invalid parameter to StringLib.StringRepeat");
         buffer = (char *)CTXMALLOC(parentCtx, tgtLen);
         if (!buffer)
             rtlThrowOutOfMemory(0, "In StringLib.StringRepeat");