* [PATCH v3] util: add bounds check to util_get_{domain,username}
@ 2019-10-17 16:12 James Prestwood
2019-10-17 16:23 ` Denis Kenzior
0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2019-10-17 16:12 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]
Two cases were using strcpy, and the other two were using strncpy.
Instead all cases can use l_strlcpy which guarentees NULL termination.
---
src/util.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/util.c b/src/util.c
index f787ce6b..a38dd380 100644
--- a/src/util.c
+++ b/src/util.c
@@ -173,10 +173,10 @@ const char *util_get_domain(const char *identity)
for (c = identity; *c; c++) {
switch (*c) {
case '\\':
- strncpy(domain, identity, c - identity);
+ memcpy(domain, identity, c - identity);
return domain;
case '@':
- strcpy(domain, c + 1);
+ l_strlcpy(domain, c + 1, sizeof(domain));
return domain;
default:
continue;
@@ -197,10 +197,10 @@ const char *util_get_username(const char *identity)
for (c = identity; *c; c++) {
switch (*c) {
case '\\':
- strcpy(username, c + 1);
+ l_strlcpy(username, c + 1, sizeof(username));
return username;
case '@':
- strncpy(username, identity, c - identity);
+ memcpy(username, identity, c - identity);
return username;
default:
continue;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] util: add bounds check to util_get_{domain,username}
2019-10-17 16:12 [PATCH v3] util: add bounds check to util_get_{domain,username} James Prestwood
@ 2019-10-17 16:23 ` Denis Kenzior
0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2019-10-17 16:23 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
Hi James,
On 10/17/19 11:12 AM, James Prestwood wrote:
> Two cases were using strcpy, and the other two were using strncpy.
> Instead all cases can use l_strlcpy which guarentees NULL termination.
> ---
> src/util.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
I split this up into two commits and reworked the commit descriptions a bit.
Applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-17 16:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-17 16:12 [PATCH v3] util: add bounds check to util_get_{domain,username} James Prestwood
2019-10-17 16:23 ` Denis Kenzior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox