Skip to content

Commit 473e002

Browse files
authored
fix: potential vulnerable cloned functions (#4996)
Fix potential vulnerable cloned functions: Security: update Lua struct package for security.
1 parent a02af96 commit 473e002

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/redis/lua/struct/lua_struct.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,12 @@ typedef struct Header {
8282
} Header;
8383

8484

85-
static int getnum (lua_State *L, const char **fmt, int df) {
85+
static int getnum (const char **fmt, int df) {
8686
if (!isdigit(**fmt)) /* no number? */
8787
return df; /* return default value */
8888
else {
8989
int a = 0;
9090
do {
91-
if (a > (INT_MAX / 10) || a * 10 > (INT_MAX - (**fmt - '0')))
92-
luaL_error(L, "integral size overflow");
9391
a = a*10 + *((*fmt)++) - '0';
9492
} while (isdigit(**fmt));
9593
return a;
@@ -110,9 +108,9 @@ static size_t optsize (lua_State *L, char opt, const char **fmt) {
110108
case 'f': return sizeof(float);
111109
case 'd': return sizeof(double);
112110
case 'x': return 1;
113-
case 'c': return getnum(L, fmt, 1);
111+
case 'c': return getnum(fmt, 1);
114112
case 'i': case 'I': {
115-
int sz = getnum(L, fmt, sizeof(int));
113+
int sz = getnum(fmt, sizeof(int));
116114
if (sz > MAXINTSIZE)
117115
luaL_error(L, "integral size %d is larger than limit of %d",
118116
sz, MAXINTSIZE);
@@ -145,7 +143,7 @@ static void controloptions (lua_State *L, int opt, const char **fmt,
145143
case '>': h->endian = BIG; return;
146144
case '<': h->endian = LITTLE; return;
147145
case '!': {
148-
int a = getnum(L, fmt, MAXALIGN);
146+
int a = getnum(fmt, MAXALIGN);
149147
if (!isp2(a))
150148
luaL_error(L, "alignment %d is not a power of 2", a);
151149
h->align = a;

0 commit comments

Comments
 (0)