aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-10-02 12:20:45 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-10-02 16:47:54 +0000
commit9f55eb4e954dd125e229bc94892e1571abd2cd65 (patch)
treee346f7352b59a1e09d7702b3e886b0986f399dd5 /epan/wslua
parent3ab013753304b7e42faf86a5b6c6522110da0432 (diff)
wslua: fix wslua file test failure
Lua 5.2.4 built with -DLUA_USE_APICHECK detected a stack issue: tshark: lapi.c:175: lua_settop: Assertion `(-(idx+1) <= (L->top - (func + 1))) && "invalid new top"' failed. Function File_read always assumes that File_read_line pushes a value on the stack (which clearly did not happen). On read failure, it would then pop the stack (tripping the assertion) to push nil. The other user (File_lines) is also affected by this change, but the Lua 5.2.4 documentation says that it should also return nil on EOF, fitting this implementation. Change-Id: I9cc8a5319523b2b56f4ae4735bbdbc1196387386 Reviewed-on: https://code.wireshark.org/review/18016 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/wslua_file.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/epan/wslua/wslua_file.c b/epan/wslua/wslua_file.c
index 51fd712b0e..cc11d07a1c 100644
--- a/epan/wslua/wslua_file.c
+++ b/epan/wslua/wslua_file.c
@@ -171,6 +171,10 @@ static int File_read_number (lua_State *L, FILE_T ft) {
}
}
+/**
+ * Attempts to read one line from the file. The actual data read is pushed on
+ * the stack (or nil on EOF).
+ */
static int File_read_line(lua_State *L, FILE_T ft) {
static gchar linebuff[MAX_LINE_LENGTH];
gint64 pos_before = file_tell(ft);
@@ -179,6 +183,8 @@ static int File_read_line(lua_State *L, FILE_T ft) {
if (file_gets(linebuff, MAX_LINE_LENGTH, ft) == NULL) {
/* No characters found, or error */
/* *err = file_error(ft, err_info); */
+ /* io.lines() and file:read() requires nil on EOF */
+ lua_pushnil(L);
return 0;
}
@@ -212,6 +218,10 @@ static int File_read_line(lua_State *L, FILE_T ft) {
#define lua_rawlen lua_objlen
#endif
+/**
+ * Reads some data and returns the number of bytes read.
+ * The actual data (possibly an empty string) is pushed on the Lua stack.
+ */
static int File_read_chars(lua_State *L, FILE_T ft, size_t n) {
size_t rlen; /* how much to read */
size_t nr; /* number of chars actually read */