From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH v3] util: add bounds check to util_get_{domain,username}
Date: Thu, 17 Oct 2019 09:12:12 -0700 [thread overview]
Message-ID: <20191017161212.22073-1-prestwoj@gmail.com> (raw)
[-- 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
next reply other threads:[~2019-10-17 16:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-17 16:12 James Prestwood [this message]
2019-10-17 16:23 ` [PATCH v3] util: add bounds check to util_get_{domain,username} Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191017161212.22073-1-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox