Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/1996?usp=email
to review the following change.
Change subject: Replace strncat with strlcat
......................................................................
Replace strncat with strlcat
Generally much better API. Not a straight-forward
replacement in many cases, trying to improve the
code generally.
Change-Id: I61e29dd2af9302b240c93735179d43c72e37b335
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/misc.c
M src/openvpn/options_parse.c
M src/openvpn/status.c
M src/openvpn/xkey_helper.c
M src/plugins/auth-pam/utils.c
5 files changed, 20 insertions(+), 23 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1996/1
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
index a75bd8f..b9cc6a2 100644
--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c
@@ -437,12 +437,11 @@
}
else
{
- if (strlen(up->password) + strlen(response) >=
USER_PASS_LEN)
+ if (strlcat(up->password, response, USER_PASS_LEN) >=
USER_PASS_LEN)
{
msg(M_FATAL,
"ERROR: could not concatenate
password/static_response: string too long");
}
- strncat(up->password, response, USER_PASS_LEN -
strlen(up->password) - 1);
}
}
#endif /* ifdef ENABLE_MANAGEMENT */
diff --git a/src/openvpn/options_parse.c b/src/openvpn/options_parse.c
index 12934ab..3d893d4 100644
--- a/src/openvpn/options_parse.c
+++ b/src/openvpn/options_parse.c
@@ -244,10 +244,7 @@
else if (is->type == IS_TYPE_BUF)
{
bool status = buf_parse(is->u.multiline, '\n', line, size);
- if ((int)strlen(line) + 1 < size)
- {
- strcat(line, "\n");
- }
+ strlcat(line, "\n", size);
return status;
}
else
diff --git a/src/openvpn/status.c b/src/openvpn/status.c
index c7d375b..981bb23 100644
--- a/src/openvpn/status.c
+++ b/src/openvpn/status.c
@@ -234,14 +234,11 @@
if (so->fd >= 0 && !so->errors)
{
- strcat(buf, "\n");
- ssize_t len = strlen(buf);
- if (len > 0)
+ size_t len = strlcat(buf, "\n", sizeof(buf));
+ ASSERT(len < sizeof(buf));
+ if (write(so->fd, buf, (unsigned int)len) != (ssize_t)len)
{
- if (write(so->fd, buf, (unsigned int)len) != len)
- {
- so->errors = true;
- }
+ so->errors = true;
}
}
diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.c
index 1149c7b..c945d18 100644
--- a/src/openvpn/xkey_helper.c
+++ b/src/openvpn/xkey_helper.c
@@ -247,7 +247,10 @@
if (is_message)
{
- strncat(alg_str, ",data=message", sizeof(alg_str) - strlen(alg_str) -
1);
+ if (strlcat(alg_str, ",data=message", sizeof(alg_str)) >=
sizeof(alg_str))
+ {
+ return -1;
+ }
}
dmsg(D_LOW, "xkey management_sign: requesting sig with algorithm <%s>",
alg_str);
diff --git a/src/plugins/auth-pam/utils.c b/src/plugins/auth-pam/utils.c
index a4d2d0b..b6b9424 100644
--- a/src/plugins/auth-pam/utils.c
+++ b/src/plugins/auth-pam/utils.c
@@ -65,23 +65,24 @@
/* state: all parameters are valid */
- const char *searching = tosearch;
-
- char temp[templen + 1];
- temp[0] = 0;
-
- const char *scratch = strstr(searching, searchfor);
+ const char *scratch = strstr(tosearch, searchfor);
if (!scratch)
{
return strdup(tosearch);
}
+ const char *searching = tosearch;
+ char temp[templen + 1] = { 0 };
+ char *target = temp;
+
while (scratch)
{
- strncat(temp, searching, (size_t)(scratch - searching));
- strcat(temp, replacewith);
+ size_t skipped = (size_t)(scratch - searching);
+ memcpy(target, searching, skipped);
+ target += skipped;
+ memcpy(target, replacewith, replacewithlen);
- searching = scratch + strlen(searchfor);
+ searching = scratch + tosearchlen;
scratch = strstr(searching, searchfor);
}
return strdup(temp);
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/1996?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e29dd2af9302b240c93735179d43c72e37b335
Gerrit-Change-Number: 1996
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel