Skip to content

Commit 17194c1

Browse files
kusmagitster
authored andcommitted
msvc: opendir: allocate enough memory
The defintion of DIR expects the allocating function to extend dd_name by over-allocating. This is not currently done in our implementation of opendir. Fix this. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 599b0bf commit 17194c1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compat/msvc.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
DIR *opendir(const char *name)
77
{
8-
int len;
8+
int len = strlen(name);
99
DIR *p;
10-
p = malloc(sizeof(DIR));
10+
p = malloc(sizeof(DIR) + len + 2);
1111
if (!p)
1212
return NULL;
1313

14-
memset(p, 0, sizeof(DIR));
15-
strncpy(p->dd_name, name, PATH_MAX);
16-
len = strlen(p->dd_name);
14+
memset(p, 0, sizeof(DIR) + len + 2);
15+
strcpy(p->dd_name, name);
1716
p->dd_name[len] = '/';
1817
p->dd_name[len+1] = '*';
1918

0 commit comments

Comments
 (0)