Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adélie Linux
gcompat
Commits
67126748
Verified
Commit
67126748
authored
May 08, 2019
by
A. Wilcox
🦊
Browse files
string: check NULL before using variables everywhere
parent
12ecdf5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
libgcompat/string.c
View file @
67126748
...
...
@@ -145,11 +145,13 @@ char *__stpncpy_chk(char *dest, const char *src, size_t n, size_t destlen)
*/
char
*
__strcat_chk
(
char
*
dest
,
const
char
*
src
,
size_t
destlen
)
{
size_t
n
=
strlen
(
src
)
+
1
;
size_t
total
=
strnlen
(
dest
,
destlen
)
+
n
;
size_t
n
;
size_t
total
;
assert
(
dest
!=
NULL
);
assert
(
src
!=
NULL
);
n
=
strlen
(
src
)
+
1
;
total
=
strnlen
(
dest
,
destlen
)
+
n
;
assert
(
destlen
>=
total
);
if
(
dest
<
src
)
{
assert
(
dest
+
total
<=
src
);
...
...
@@ -215,10 +217,11 @@ char *__strdup(const char *string)
*/
char
*
__strncat_chk
(
char
*
dest
,
const
char
*
src
,
size_t
n
,
size_t
destlen
)
{
size_t
total
=
strnlen
(
dest
,
destlen
)
+
n
+
1
;
size_t
total
;
assert
(
dest
!=
NULL
);
assert
(
src
!=
NULL
);
total
=
strnlen
(
dest
,
destlen
)
+
n
+
1
;
assert
(
destlen
>=
total
);
if
(
dest
<
src
)
{
assert
(
dest
+
total
<=
src
);
...
...
Write
Preview
Supports
Markdown
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