From d0e6ab38dfa576fc852c3fac2270f4a3cf231b01 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Tue, 11 Aug 2015 00:08:49 +0200 Subject: [PATCH] add write error detection in node_compile() --- app/modules/node.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/modules/node.c b/app/modules/node.c index a57fd6cb..65438cde 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -382,7 +382,10 @@ static int node_compile( lua_State* L ) int result = luaU_dump(L, f, writer, &file_fd, stripping); lua_unlock(L); - fs_flush(file_fd); + if (fs_flush(file_fd) < 0) { // result codes aren't propagated by flash_fs.h + // overwrite Lua error, like writer() does in case of a file io error + result = 1; + } fs_close(file_fd); file_fd = FS_OPEN_OK - 1; @@ -392,6 +395,9 @@ static int node_compile( lua_State* L ) if (result == LUA_ERR_CC_NOTINTEGER) { return luaL_error(L, "target lua_Number is integral but fractional value found"); } + if (result == 1) { // result status generated by writer() or fs_flush() fail + return luaL_error(L, "writing to file failed"); + } return 0; }