All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: selinux@tycho.nsa.gov
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [PATCH 3/4] libselinux: avcstat: fix build warning
Date: Thu,  3 May 2018 14:48:44 -0400	[thread overview]
Message-ID: <20180503184845.19790-4-sds@tycho.nsa.gov> (raw)
In-Reply-To: <20180503184845.19790-1-sds@tycho.nsa.gov>

Fix the following build warning.

avcstat.c: In function ‘main’:
avcstat.c:113:4: error: ‘strncpy’ specified bound 4096 equals destination size [-Werror=stringop-truncation]
    strncpy(avcstatfile, optarg, sizeof avcstatfile);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
---
 libselinux/utils/avcstat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
index 5ff582b8..884a10bf 100644
--- a/libselinux/utils/avcstat.c
+++ b/libselinux/utils/avcstat.c
@@ -110,7 +110,8 @@ int main(int argc, char **argv)
 			cumulative = 1;
 			break;
 		case 'f':
-			strncpy(avcstatfile, optarg, sizeof avcstatfile);
+			strncpy(avcstatfile, optarg, sizeof(avcstatfile) - 1);
+			avcstatfile[sizeof(avcstatfile)-1] = '\0';
 			break;
 		case 'h':
 		case '-':
-- 
2.14.3

  parent reply	other threads:[~2018-05-03 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 18:48 [PATCH 0/4] Fix build warnings with gcc 8 Stephen Smalley
2018-05-03 18:48 ` [PATCH 1/4] libsepol: remove unused function and type Stephen Smalley
2018-05-03 18:48 ` [PATCH 2/4] libselinux: fix build warning in save_booleans() Stephen Smalley
2018-05-03 18:48 ` Stephen Smalley [this message]
2018-05-03 18:48 ` [PATCH 4/4] libselinux: audit2why: fix build warnings Stephen Smalley
2018-05-08 12:17 ` [PATCH 0/4] Fix build warnings with gcc 8 Stephen Smalley

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=20180503184845.19790-4-sds@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /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.