From 3c15d99cec8b5ee2d117d9ebbe20d7031acbd131 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Fri, 9 Jul 2021 08:37:56 +0800 Subject: [PATCH] add default value for process:read* functions This time with more checks against scrutiny --- src/api/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/process.c b/src/api/process.c index ad2a7321..4b018e4c 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -10,6 +10,8 @@ #include #include "api.h" +#define READ_BUF_SIZE 2048 + #define L_GETTABLE(L, idx, key, conv, def) ( \ lua_getfield(L, idx, key), \ conv(L, -1, def) \ @@ -228,7 +230,7 @@ static int f_returncode(lua_State *L) static int g_read(lua_State* L, int stream) { process_t* self = (process_t*) luaL_checkudata(L, 1, API_TYPE_PROCESS); - unsigned long read_size = luaL_checkunsigned(L, 2); + unsigned long read_size = luaL_optunsigned(L, 2, READ_BUF_SIZE); luaL_Buffer b; uint8_t* buffer = (uint8_t*) luaL_buffinitsize(L, &b, read_size); @@ -266,6 +268,9 @@ static int f_read(lua_State* L) { int stream = luaL_checknumber(L, 2); lua_remove(L, 2); + if (stream > REPROC_STREAM_ERR) + L_RETURN_REPROC_ERROR(L, REPROC_EINVAL); + return g_read(L, stream); }