From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0D78E1384B4 for ; Thu, 26 Nov 2015 08:43:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 423C321C00E; Thu, 26 Nov 2015 08:43:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D06C821C00E for ; Thu, 26 Nov 2015 08:43:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8C62733FA71 for ; Thu, 26 Nov 2015 08:43:42 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AD20599D for ; Thu, 26 Nov 2015 08:43:37 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1448527307.335e3c30ebd98959a53c22b12b17f907d7def48c.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: xfuncs.h X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 335e3c30ebd98959a53c22b12b17f907d7def48c X-VCS-Branch: master Date: Thu, 26 Nov 2015 08:43:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 98577930-40b1-42e5-816d-e02781d335b8 X-Archives-Hash: cd7e026551e29fe641bfe17f8be963ab commit: 335e3c30ebd98959a53c22b12b17f907d7def48c Author: Mike Frysinger gentoo org> AuthorDate: Thu Nov 26 08:41:47 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Nov 26 08:41:47 2015 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=335e3c30 xarray: move ele update to after bounds check Even though we don't use the loaded ele value until after we check the bounds of the counter, it makes ASAN unhappy, and might cause a load of invalid memory. URL: https://bugs.gentoo.org/553368 Reported-by: Hanno Boeck gentoo.org> xfuncs.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xfuncs.h b/xfuncs.h index 82f5da0..61577ec 100644 --- a/xfuncs.h +++ b/xfuncs.h @@ -27,10 +27,14 @@ void xarraypush(array_t *array, const void *ele, size_t ele_len); #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/) void xarrayfree(array_t *array); #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size)) +/* The assignment after the check is unfortunate as we do a non-NULL check (we + * already do not permit pushing of NULL pointers), but we can't put it in the + * increment phase as that will cause a load beyond the bounds of valid memory. + */ #define array_for_each(arr, n, ele) \ for (n = 0, ele = array_cnt(arr) ? arr->eles[n] : NULL; \ - n < array_cnt(arr); \ - ele = arr->eles[++n]) + n < array_cnt(arr) && (ele = arr->eles[n]); \ + ++n) #define array_init_decl { .eles = NULL, .num = 0, } #define array_cnt(arr) (arr)->num char *array_flatten_str(array_t *array);