]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
rand: fix 'alnum': array is too small to include a terminating null character
authorDaniel Stenberg <daniel@haxx.se>
Sat, 16 Sep 2023 20:37:28 +0000 (22:37 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 17 Sep 2023 15:43:52 +0000 (17:43 +0200)
It was that small on purpose, but this change now adds the null byte to
avoid the error.

Follow-up to 3aa3cc9b052353b1

Reported-by: Dan Fandrich
Ref: #11838
Closes #11870

lib/rand.c

index 8cac9383acaf51344dc50c039a2d5bb1c21648d3..d7935b397e67e94fea39bba59f2cf03a4d9c4893 100644 (file)
@@ -275,14 +275,14 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd,
  * alphanumerical chars PLUS a null-terminating byte.
  */
 
-static const char alnum[26 + 26 + 10] =
+static const char alnum[] =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
 CURLcode Curl_rand_alnum(struct Curl_easy *data, unsigned char *rnd,
                          size_t num)
 {
   CURLcode result = CURLE_OK;
-  const int alnumspace = sizeof(alnum);
+  const int alnumspace = sizeof(alnum) - 1;
   unsigned int r;
   DEBUGASSERT(num > 1);