From 9eddebd7034e3299ea932883ad5782a292cf0aca Mon Sep 17 00:00:00 2001 From: Denis Ollier Date: Thu, 9 Aug 2018 23:05:04 +0200 Subject: [PATCH] Fix out of bounds compilation warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When compiling with -D_FORTIFY_SOURCE=2, gcc raises the following warning: In file included from /usr/include/string.h:494, from /build/libsolv/src/libsolv-0.6.35/src/policy.c:16: In function ‘memcpy’, inlined from ‘urpm_reorder.isra.18’ at /build/libsolv/src/libsolv-0.6.35/src/policy.c:1239:9: /usr/include/bits/string_fortified.h:34:10: warning: ‘__builtin_memcpy’ forming offset 8 is out of the bounds [0, 7] [-Warray-bounds] return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Culprit code is: memcpy(kn, "kernel", 8); memcpy(kn + 6, flavor, release - flavor + 1); The first memcpy copies 8 bytes whereas the string "kernel" as only 7 bytes. It does not have serious consequence since the second memcpy overwrites the unwanted byte. Anyway, it is better to fix it. --- src/policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy.c b/src/policy.c index a38dea05..191327a1 100644 --- a/src/policy.c +++ b/src/policy.c @@ -1236,7 +1236,7 @@ urpm_reorder(Solver *solv, Queue *plist) { char kn[256]; Id p, pp, knid; - memcpy(kn, "kernel", 8); + memcpy(kn, "kernel", 7); memcpy(kn + 6, flavor, release - flavor + 1); memcpy(kn + 6 + (release - flavor) + 1, sn, flavor - sn); strcpy(kn + 6 + (release + 1 - sn), release); -- 2.47.2