aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2026-08-29 17:19:19 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2026-08-29 17:22:41 +0200
commit827ae20771d34912a8f79b50dc68e6430945b9eb (patch)
tree34357203cc3431096167a7bf6feb4ff2dca1ee8b /src/buffer.c
parent8cbbce56e64c84b53593c815f6dcdd9214897b74 (diff)
downloadluasocket-827ae20771d34912a8f79b50dc68e6430945b9eb.tar.gz
luasocket-827ae20771d34912a8f79b50dc68e6430945b9eb.tar.bz2
luasocket-827ae20771d34912a8f79b50dc68e6430945b9eb.zip
fix(receive): guard numeric pattern against size_t overflow on cast
Same class of bug as the maxsize cast: a double larger than SIZE_MAX cast to size_t is undefined behavior. Bound-check the numeric receive pattern before the cast, and cover it with a test.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 5f06fc1..3d48a09 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -125,7 +125,8 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
125 /* ---- validation: must precede timeout_markstart() and any I/O ---- */ 125 /* ---- validation: must precede timeout_markstart() and any I/O ---- */
126 if (numeric) { 126 if (numeric) {
127 double n = lua_tonumber(L, 2); 127 double n = lua_tonumber(L, 2);
128 luaL_argcheck(L, n >= 0, 2, "invalid receive pattern"); 128 luaL_argcheck(L, n >= 0 && n < (lua_Number) ((size_t) -1), 2,
129 "invalid receive pattern");
129 wanted = (size_t) n; 130 wanted = (size_t) n;
130 } else { 131 } else {
131 const char *p = luaL_optstring(L, 2, "*l"); 132 const char *p = luaL_optstring(L, 2, "*l");