lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <72H9kav0twfAapoNgg-Q4eYD1U-oNt8RCfc27ftyekmZTePdhyHG8hnFoxrzBRmhXkwkhJkxa9_xNp_tV9Y2yYhKHuWbHsGb9Uc-wmgAEYM=@protonmail.ch>
Date:   Wed, 15 Aug 2018 13:46:37 +0000
From:   ykp@...tonmail.ch
To:     "linux-ext4@...r.kernel.org" <linux-ext4@...r.kernel.org>
Subject: [PATCH] Fix gcc-wall warnings about strncpy

>From 12109693995386c9941129e65078a4305e72936e Mon Sep 17 00:00:00 2001
From: Vladyslav Tsilytskyi <ykp@...tonmail.ch>
Date: Wed, 15 Aug 2018 15:25:24 +0200
Subject: [PATCH] Fix -Wsizeof-pointer-memaccess warnings

strncpy's last parameter was wrong - there was a length
of source. In order to use function correctly (and prevent
buffer overflows) last argument should denote destination's
buffer capacity.

Signed-off-by: Vladyslav Tsilytskyi <ykp@...tonmail.ch>
---
 lib/e2p/ls.c            | 10 ++++------
 lib/support/plausible.c |  3 +--
 misc/mke2fs.c           |  2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c
index a7586e09..32ced7f2 100644
--- a/lib/e2p/ls.c
+++ b/lib/e2p/ls.c
@@ -234,13 +234,13 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
 				  EXT2_BLOCK_SIZE(sb));
 	if (sb->s_volume_name[0]) {
 		memset(buf, 0, sizeof(buf));
-		strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name));
+		strncpy(buf, sb->s_volume_name, sizeof(buf));
 	} else
 		strcpy(buf, "<none>");
 	fprintf(f, "Filesystem volume name:   %s\n", buf);
 	if (sb->s_last_mounted[0]) {
 		memset(buf, 0, sizeof(buf));
-		strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted));
+		strncpy(buf, sb->s_last_mounted, sizeof(buf));
 	} else
 		strcpy(buf, "<not available>");
 	fprintf(f, "Last mounted on:          %s\n", buf);
@@ -420,8 +420,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
 		tm = sb->s_first_error_time;
 		fprintf(f, "First error time:         %s", ctime(&tm));
 		memset(buf, 0, sizeof(buf));
-		strncpy(buf, (char *)sb->s_first_error_func,
-			sizeof(sb->s_first_error_func));
+		strncpy(buf, (char *)sb->s_first_error_func, sizeof(buf));
 		fprintf(f, "First error function:     %s\n", buf);
 		fprintf(f, "First error line #:       %u\n",
 			sb->s_first_error_line);
@@ -434,8 +433,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
 		tm = sb->s_last_error_time;
 		fprintf(f, "Last error time:          %s", ctime(&tm));
 		memset(buf, 0, sizeof(buf));
-		strncpy(buf, (char *)sb->s_last_error_func,
-			sizeof(sb->s_last_error_func));
+		strncpy(buf, (char *)sb->s_last_error_func, sizeof(buf));
 		fprintf(f, "Last error function:      %s\n", buf);
 		fprintf(f, "Last error line #:        %u\n",
 			sb->s_last_error_line);
diff --git a/lib/support/plausible.c b/lib/support/plausible.c
index a7268980..6a6da61f 100644
--- a/lib/support/plausible.c
+++ b/lib/support/plausible.c
@@ -113,8 +113,7 @@ static void print_ext2_info(const char *device)
 		tm = sb->s_mtime;
 		if (sb->s_last_mounted[0]) {
 			memset(buf, 0, sizeof(buf));
-			strncpy(buf, sb->s_last_mounted,
-				sizeof(sb->s_last_mounted));
+			strncpy(buf, sb->s_last_mounted, sizeof(buf));
 			printf(_("\tlast mounted on %s on %s"), buf,
 			       ctime(&tm));
 		} else
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index b23ea766..2afe91cc 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -674,7 +674,7 @@ static void show_stats(ext2_filsys fs)
 		       ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));

 	memset(buf, 0, sizeof(buf));
-	strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
+	strncpy(buf, s->s_volume_name, sizeof(buf));
 	printf(_("Filesystem label=%s\n"), buf);
 	os = e2p_os2string(fs->super->s_creator_os);
 	if (os)
--
2.17.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ