Skip to content

Commit 1ed95ad

Browse files
trawickFelipe Zimmerle
authored andcommitted
Fix invalid storage reference by apr_psprintf() when creating a string from salt[]. salt[] is not '\0'-terminated, so apr_psprintf() needs to be told the extent of the bytes to read.
It is easy to test old/new code standalone with valgrind; jst insert the getkey() function into this template: -----------getkey() goes here----------------- int main(void) { apr_pool_t *p; apr_initialize(); apr_pool_create(&p, NULL); printf("%s\n", getkey(p)); return 0; }
1 parent a9a3925 commit 1ed95ad

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

apache2/msc_crypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ char *getkey(apr_pool_t *mp) {
152152
char salt[64];
153153

154154
apr_generate_random_bytes(salt, sizeof(salt));
155-
key = apr_psprintf(mp,"%s",salt);
155+
key = apr_psprintf(mp,"%.*s",(int)sizeof(salt),salt);
156156

157157
apr_sha1_init (&ctx);
158158
apr_sha1_update (&ctx, (const char*)key, strlen(key));
159159
apr_sha1_update (&ctx, "\0", 1);
160160

161161
apr_generate_random_bytes(salt, sizeof(salt));
162-
value = apr_psprintf(mp,"%s",salt);
162+
value = apr_psprintf(mp,"%.*s",(int)sizeof(salt),salt);
163163

164164
apr_sha1_update (&ctx, value, strlen (value));
165165
apr_sha1_final (digest, &ctx);

0 commit comments

Comments
 (0)