lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 * Fixed bug: segfault (null pointer dereference) in dup(x,nil).

 * Fixed bug: non-conforming mode "rw" changed to "w+".  POSIX specifies "w+" or
   "r+" for read/write open.  "rw" is incorrect and fails to open for writing
   on GNU libc's fdopen().

Signed-off-by: David Favro <lua@meta-dynamic.com>
---
 lposix.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lposix.c b/lposix.c
index d3eb910..f5e1c34 100644
--- a/lposix.c
+++ b/lposix.c
@@ -614,7 +614,7 @@ static const char *filemode(int fd)
 	switch (mode & O_ACCMODE) {
 		case O_RDONLY:  m = "r"; break;
 		case O_WRONLY:  m = "w"; break;
-		default:    	m = "rw"; break;
+		default:    	m = "w+"; break;
 	}
 	return m;
 }
@@ -622,16 +622,16 @@ static const char *filemode(int fd)
 static int Pdup(lua_State *L)			/** dup(old,[new]) */
 {
 	FILE **oldf = (FILE**)luaL_checkudata(L, 1, LUA_FILEHANDLE);
-  	FILE **newf = (FILE **)lua_touserdata(L, 2);
+	FILE **newf = (FILE**)lua_touserdata(L, 2);
 	int fd;
-	const char *msg = "dup2";
-	fflush(*newf);
+	const char * msg;
 	if (newf == NULL) {
 		fd = dup(fileno(*oldf));
 		msg = "dup";
 	} else {
 		fflush(*newf);
 		fd = dup2(fileno(*oldf), fileno(*newf));
+		msg = "dup2";
 	}
 
 	if ((fd < 0) || !pushfile(L, fd, filemode(fd)))
-- 
1.7.0.4