From: Denis Ollier Date: Thu, 9 Aug 2018 21:05:04 +0000 (+0200) Subject: Fix out of bounds compilation warning X-Git-Tag: 0.6.36~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F277%2Fhead;p=thirdparty%2Flibsolv.git Fix out of bounds compilation warning 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. --- 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);