Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6521a6b1
Commit
6521a6b1
authored
Dec 13, 2015
by
Sun He
Committed by
antirez
Dec 14, 2015
Browse files
lua_struct.c/getnum: throw error if overflow happen
Fix issue #2855
parent
87615a81
Changes
1
Hide whitespace changes
Inline
Side-by-side
deps/lua/src/lua_struct.c
View file @
6521a6b1
...
@@ -89,12 +89,14 @@ typedef struct Header {
...
@@ -89,12 +89,14 @@ typedef struct Header {
}
Header
;
}
Header
;
static
int
getnum
(
const
char
**
fmt
,
int
df
)
{
static
int
getnum
(
lua_State
*
L
,
const
char
**
fmt
,
int
df
)
{
if
(
!
isdigit
(
**
fmt
))
/* no number? */
if
(
!
isdigit
(
**
fmt
))
/* no number? */
return
df
;
/* return default value */
return
df
;
/* return default value */
else
{
else
{
int
a
=
0
;
int
a
=
0
;
do
{
do
{
if
(
a
>
(
INT_MAX
/
10
)
||
a
*
10
>
(
INT_MAX
-
(
**
fmt
-
'0'
)))
luaL_error
(
L
,
"integral size overflow"
);
a
=
a
*
10
+
*
((
*
fmt
)
++
)
-
'0'
;
a
=
a
*
10
+
*
((
*
fmt
)
++
)
-
'0'
;
}
while
(
isdigit
(
**
fmt
));
}
while
(
isdigit
(
**
fmt
));
return
a
;
return
a
;
...
@@ -115,9 +117,9 @@ static size_t optsize (lua_State *L, char opt, const char **fmt) {
...
@@ -115,9 +117,9 @@ static size_t optsize (lua_State *L, char opt, const char **fmt) {
case
'f'
:
return
sizeof
(
float
);
case
'f'
:
return
sizeof
(
float
);
case
'd'
:
return
sizeof
(
double
);
case
'd'
:
return
sizeof
(
double
);
case
'x'
:
return
1
;
case
'x'
:
return
1
;
case
'c'
:
return
getnum
(
fmt
,
1
);
case
'c'
:
return
getnum
(
L
,
fmt
,
1
);
case
'i'
:
case
'I'
:
{
case
'i'
:
case
'I'
:
{
int
sz
=
getnum
(
fmt
,
sizeof
(
int
));
int
sz
=
getnum
(
L
,
fmt
,
sizeof
(
int
));
if
(
sz
>
MAXINTSIZE
)
if
(
sz
>
MAXINTSIZE
)
luaL_error
(
L
,
"integral size %d is larger than limit of %d"
,
luaL_error
(
L
,
"integral size %d is larger than limit of %d"
,
sz
,
MAXINTSIZE
);
sz
,
MAXINTSIZE
);
...
@@ -150,7 +152,7 @@ static void controloptions (lua_State *L, int opt, const char **fmt,
...
@@ -150,7 +152,7 @@ static void controloptions (lua_State *L, int opt, const char **fmt,
case
'>'
:
h
->
endian
=
BIG
;
return
;
case
'>'
:
h
->
endian
=
BIG
;
return
;
case
'<'
:
h
->
endian
=
LITTLE
;
return
;
case
'<'
:
h
->
endian
=
LITTLE
;
return
;
case
'!'
:
{
case
'!'
:
{
int
a
=
getnum
(
fmt
,
MAXALIGN
);
int
a
=
getnum
(
L
,
fmt
,
MAXALIGN
);
if
(
!
isp2
(
a
))
if
(
!
isp2
(
a
))
luaL_error
(
L
,
"alignment %d is not a power of 2"
,
a
);
luaL_error
(
L
,
"alignment %d is not a power of 2"
,
a
);
h
->
align
=
a
;
h
->
align
=
a
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment