Thread (18 messages) flat view 18 messages, 2 authors, 2016-06-15
DORMANTno replies

Revision rfc of 2 in this series.

Revisions (2)
  1. rfc current
  2. v2 [diff vs current]

[RFC PATCH 2/6] msvc: opendir: allocate enough memory

From: Erik Faye-Lund <hidden>
Date: 2016-06-15 22:50:05
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 compat/msvc.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/compat/msvc.c b/compat/msvc.c
index db3df51..205304e 100644
--- a/compat/msvc.c
+++ b/compat/msvc.c
@@ -5,12 +5,11 @@
 
 DIR *opendir(const char *name)
 {
-	int len;
+	int len = strlen(p->dd_name);
 	DIR *p;
-	p = xmalloc(sizeof(DIR));
-	memset(p, 0, sizeof(DIR));
-	strncpy(p->dd_name, name, PATH_MAX);
-	len = strlen(p->dd_name);
+	p = xmalloc(sizeof(DIR) + len + 2);
+	memset(p, 0, sizeof(DIR) + len + 2);
+	strcpy(p->dd_name, name);
 	p->dd_name[len] = '/';
 	p->dd_name[len+1] = '*';
 
-- 
1.7.3.2.493.ge4bf7
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help