From patchwork Wed Aug 15 13:46:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ykp@protonmail.ch X-Patchwork-Id: 957925 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.ch Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=protonmail.ch header.i=@protonmail.ch header.b="aQTvrpRj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41r9jx1ny4z9sBZ for ; Wed, 15 Aug 2018 23:46:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729376AbeHOQi6 (ORCPT ); Wed, 15 Aug 2018 12:38:58 -0400 Received: from mail-40136.protonmail.ch ([185.70.40.136]:14294 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729125AbeHOQi5 (ORCPT ); Wed, 15 Aug 2018 12:38:57 -0400 Date: Wed, 15 Aug 2018 13:46:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.ch; s=default; t=1534340801; bh=uJoUr6Le2XbMadKlO87SLgYE7qVO5OlQ+AT7Y+doS1A=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=aQTvrpRjITEe4+FZ2dm5BXPmulboAT4XIybkJxyGtPXinyrp+pZyLOhAyfZLol0r5 ooYcww4oCs/wVEdYka2uHp60f6mLnqCVLFLEXD5g0pr7PiQygqnTH9+VNoELA4AcGL bnibG/4y78KYuSK/wHP8ntDNFdDCgfvhlljo0gDM= To: "linux-ext4@vger.kernel.org" From: ykp@protonmail.ch Reply-To: ykp@protonmail.ch Subject: [PATCH] Fix gcc-wall warnings about strncpy Message-ID: <72H9kav0twfAapoNgg-Q4eYD1U-oNt8RCfc27ftyekmZTePdhyHG8hnFoxrzBRmhXkwkhJkxa9_xNp_tV9Y2yYhKHuWbHsGb9Uc-wmgAEYM=@protonmail.ch> Feedback-ID: YAgkuq_oFuNPZqxe61TkSEEen06gSt05I78Z79qvyG2Rdsm-uZo1DGGDUO9XCP-fqPZVfvE-4ddLwh9yNWy3_Q==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.1 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.protonmail.ch Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From 12109693995386c9941129e65078a4305e72936e Mon Sep 17 00:00:00 2001 From: Vladyslav Tsilytskyi 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 --- lib/e2p/ls.c | 10 ++++------ lib/support/plausible.c | 3 +-- misc/mke2fs.c | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) -- 2.17.1 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, ""); 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, ""); 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)