[PATCH 3/4] libselinux: avcstat: fix build warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux