All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Haines <richard_c_haines@btinternet.com>
To: selinux@vger.kernel.org, bill.c.roberts@gmail.com, sds@tycho.nsa.gov
Cc: Richard Haines <richard_c_haines@btinternet.com>
Subject: [PATCH V2] selinux: Fix strncpy in libselinux and libsepol
Date: Sun,  2 Jun 2019 10:16:13 +0100	[thread overview]
Message-ID: <20190602091613.5102-1-richard_c_haines@btinternet.com> (raw)

When building with gcc9, get build errors such as:

genbools.c:24:2: error: ‘strncpy’ output may be truncated copying 8191
bytes from a string of length 8191 [-Werror=stringop-truncation]
   24 |  strncpy(dest, ptr, size);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
---
V2 Change
Remove buffer resizing and just fix buffer lengths to match for strncpy.
To test booleans.c use security_load_booleans(3)
To test genbools.c generate a policy 'booleans' file and run semodule -B

 libselinux/src/booleans.c | 2 +-
 libsepol/src/genbools.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libselinux/src/booleans.c b/libselinux/src/booleans.c
index ab1e0754..e1079fb9 100644
--- a/libselinux/src/booleans.c
+++ b/libselinux/src/booleans.c
@@ -358,7 +358,7 @@ static int process_boolean(char *buffer, char *name, int namesize, int *val)
 		return -1;
 	}
 	strncpy(name1, tok, BUFSIZ - 1);
-	strtrim(name, name1, namesize - 1);
+	strtrim(name, name1, namesize);
 
 	tok = strtok_r(NULL, "\0", &ptr);
 	if (!tok) {
diff --git a/libsepol/src/genbools.c b/libsepol/src/genbools.c
index d4a2df62..c6595b80 100644
--- a/libsepol/src/genbools.c
+++ b/libsepol/src/genbools.c
@@ -49,7 +49,7 @@ static int process_boolean(char *buffer, char *name, int namesize, int *val)
 		return -1;
 	}
 	strncpy(name1, tok, BUFSIZ - 1);
-	strtrim(name, name1, namesize - 1);
+	strtrim(name, name1, namesize);
 
 	tok = strtok_r(NULL, "\0", &ptr);
 	if (!tok) {
-- 
2.21.0


                 reply	other threads:[~2019-06-02 10:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190602091613.5102-1-richard_c_haines@btinternet.com \
    --to=richard_c_haines@btinternet.com \
    --cc=bill.c.roberts@gmail.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.