Blob Blame History Raw
From b0f95e3954f85d97a99f8a08645418945484dbca Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Wed, 1 Sep 2021 08:00:00 +0000
Subject: [PATCH 2/3] common.c: fix strncat usage

When quota is configured using --enable-werror, gcc -flto fails with
the following diagnostics:

In function 'strncat',
    inlined from 'sstrncat' at common.c:113:2,
    inlined from 'get_proc_num' at quotastats.c:46:2:
/usr/include/bits/string_fortified.h:122:10: error: '__builtin___strncat_chk' specified bound 4096 equals destination size [-Werror=str
ingop-overflow=]
  122 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^

This diagnostics is correct: when "src" contains "len" or more bytes,
strncat() writes "len"+1 bytes to "dest" ("len" from "src" plus
the terminating null byte).

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common.c b/common.c
index 8be0428..b3e5ad2 100644
--- a/common.c
+++ b/common.c
@@ -110,8 +110,7 @@ void sstrncpy(char *d, const char *s, size_t len)
 
 void sstrncat(char *d, const char *s, size_t len)
 {
-	strncat(d, s, len);
-	d[len - 1] = 0;
+	strncat(d, s, len - 1);
 }
 
 char *sstrdup(const char *s)
-- 
2.31.1