aboutsummaryrefslogtreecommitdiff
path: root/libexec/flua/modules
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2026-01-28 15:37:04 +0000
committerKyle Evans <kevans@FreeBSD.org>2026-01-28 15:43:14 +0000
commitb41b6fdb3a1635de4c2a9280aab12b83e3aeffc5 (patch)
tree4032a99d0814bc7a46b89bbecbfada8bbac73797 /libexec/flua/modules
parent0cca6277499febef57149e8999ecd1a42ef1dfd3 (diff)
Diffstat (limited to 'libexec/flua/modules')
-rw-r--r--libexec/flua/modules/lposix.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c
index 75cdd345aeaa..a25e875045a2 100644
--- a/libexec/flua/modules/lposix.c
+++ b/libexec/flua/modules/lposix.c
@@ -8,6 +8,7 @@
#include <sys/utsname.h>
#include <sys/wait.h>
+#include <assert.h>
#include <errno.h>
#include <fnmatch.h>
#include <grp.h>
@@ -254,7 +255,7 @@ lua_execp(lua_State *L)
}
argv[argc + 1] = NULL;
- execvp(file, (char **)argv);
+ execvp(file, __DECONST(char **, argv));
error = errno;
lua_pushnil(L);
@@ -386,7 +387,7 @@ lua_read(lua_State *L)
char *buf;
ssize_t ret;
size_t sz;
- int error, fd;
+ int error = 0, fd;
enforce_max_args(L, 2);
fd = luaL_checkinteger(L, 1);
@@ -398,8 +399,10 @@ lua_read(lua_State *L)
}
buf = malloc(sz);
- if (buf == NULL)
+ if (buf == NULL) {
+ error = errno;
goto err;
+ }
/*
* For 0-byte reads, we'll still push the empty string and let the
@@ -412,12 +415,13 @@ lua_read(lua_State *L)
error = errno; /* Save to avoid clobber by free() */
free(buf);
- if (error != 0)
+ if (ret < 0)
goto err;
/* Just the string pushed. */
return (1);
err:
+ assert(error != 0);
lua_pushnil(L);
lua_pushstring(L, strerror(error));
lua_pushinteger(L, error);