blob: 94e0466f438ecea62a6410c5c42e93605d9b3cff [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- ../libcgi-1.0-last/libcgi-1.0/src/md5.c 2014-10-28 15:16:27.000000000 +0800
2+++ libcgi-1.0/src/md5.c 2015-05-20 15:36:47.000000000 +0800
3@@ -65,17 +65,18 @@
4 **/
5 char *md5(const char *str)
6 {
7- char *tmp, buf[32];
8+ char *tmp, buf[32] = { 0 };
9 int i, str_size;
10 unsigned char md[16];
11 MD5_CTX context;
12
13 // allocating a pointer to the string
14 str_size = strlen(str) + 1;
15- tmp = (char *)malloc(str_size);
16+ tmp = (char *)malloc(32 + 1);
17 if (tmp == NULL)
18 libcgi_error(E_MEMORY, "%s, line %s", __FILE__, __LINE__);
19
20+ memset(tmp, 0, 32 + 1);
21 // initializing a context that will content the encrypted string
22 MD5Init(&context);
23 MD5Update(&context, str, strlen(str));
24@@ -85,12 +86,12 @@
25
26 // here, the loop is less than 32 because a md5 string can content
27 // just 32 bytes
28- for(i = 0; i < 32; i++) {
29+ for(i = 0; i <16; i++) {
30 snprintf(buf, sizeof(float), "%02x", md[i]);
31 strncat(tmp, buf, sizeof(float));
32 }
33
34- tmp[i] = '\0';
35+ tmp[32] = '\0';
36
37 // returning a encrypted string
38 return tmp;