Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
00b82683
Commit
00b82683
authored
Feb 02, 2022
by
Björn Svensson
Browse files
Handle overflows as errors instead of asserting
parent
64062a1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
sds.c
View file @
00b82683
...
@@ -90,7 +90,7 @@ sds sdsnewlen(const void *init, size_t initlen) {
...
@@ -90,7 +90,7 @@ sds sdsnewlen(const void *init, size_t initlen) {
int
hdrlen
=
sdsHdrSize
(
type
);
int
hdrlen
=
sdsHdrSize
(
type
);
unsigned
char
*
fp
;
/* flags pointer. */
unsigned
char
*
fp
;
/* flags pointer. */
assert
(
initlen
+
hdrlen
+
1
>
initlen
)
;
/* Catch size_t overflow */
if
(
hdrlen
+
initlen
+
1
<=
initlen
)
return
NULL
;
/* Catch size_t overflow */
sh
=
s_malloc
(
hdrlen
+
initlen
+
1
);
sh
=
s_malloc
(
hdrlen
+
initlen
+
1
);
if
(
sh
==
NULL
)
return
NULL
;
if
(
sh
==
NULL
)
return
NULL
;
if
(
!
init
)
if
(
!
init
)
...
@@ -207,7 +207,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
...
@@ -207,7 +207,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
len
=
sdslen
(
s
);
len
=
sdslen
(
s
);
sh
=
(
char
*
)
s
-
sdsHdrSize
(
oldtype
);
sh
=
(
char
*
)
s
-
sdsHdrSize
(
oldtype
);
reqlen
=
newlen
=
(
len
+
addlen
);
reqlen
=
newlen
=
(
len
+
addlen
);
assert
(
newlen
>
len
)
;
/* Catch size_t overflow */
if
(
newlen
<=
len
)
return
NULL
;
/* Catch size_t overflow */
if
(
newlen
<
SDS_MAX_PREALLOC
)
if
(
newlen
<
SDS_MAX_PREALLOC
)
newlen
*=
2
;
newlen
*=
2
;
else
else
...
@@ -221,7 +221,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
...
@@ -221,7 +221,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
if
(
type
==
SDS_TYPE_5
)
type
=
SDS_TYPE_8
;
if
(
type
==
SDS_TYPE_5
)
type
=
SDS_TYPE_8
;
hdrlen
=
sdsHdrSize
(
type
);
hdrlen
=
sdsHdrSize
(
type
);
assert
(
hdrlen
+
newlen
+
1
>
reqlen
)
;
/* Catch size_t overflow */
if
(
hdrlen
+
newlen
+
1
<=
reqlen
)
return
NULL
;
/* Catch size_t overflow */
if
(
oldtype
==
type
)
{
if
(
oldtype
==
type
)
{
newsh
=
s_realloc
(
sh
,
hdrlen
+
newlen
+
1
);
newsh
=
s_realloc
(
sh
,
hdrlen
+
newlen
+
1
);
if
(
newsh
==
NULL
)
return
NULL
;
if
(
newsh
==
NULL
)
return
NULL
;
...
...
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