@matheusbsbs / matheus-bagliano / commits / 17194c1e96
Fork 0

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>

Erik Faye-Lund committed Nov 23, 2010 at 19:38 UTC 17194c1e96eddb43d2608fe7bd121256d17118ee
1 file changed +4 -5
compat/msvc.c
+4 -5
@@ -5,15 +5,14 @@
5
6 DIR *opendir(const char *name)
7 {
8 - int len;
8 + int len = strlen(name);
9 DIR *p;
10 - p = malloc(sizeof(DIR));
10 + p = malloc(sizeof(DIR) + len + 2);
11 if (!p)
12 return NULL;
13
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);
16 p->dd_name[len] = '/';
17 p->dd_name[len+1] = '*';
18