From unknown Wed Aug 20 03:37:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#19784: build fails on make-prime-list when asan is enabled Resent-From: Yury Usishchev Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 05 Feb 2015 16:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19784 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 19784@debbugs.gnu.org Cc: Vyacheslav Barinov , =?UTF-8?Q?=EB=B0=95=EC=B0=AC=ED=98=B8?= X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.142315512712051 (code B ref -1); Thu, 05 Feb 2015 16:53:02 +0000 Received: (at submit) by debbugs.gnu.org; 5 Feb 2015 16:52:07 +0000 Received: from localhost ([127.0.0.1]:34931 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJPev-00038I-VK for submit@debbugs.gnu.org; Thu, 05 Feb 2015 11:52:06 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40725) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJOFF-0000xQ-QD for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJOF8-0002gR-Hg for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:23 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_MANY_HDRS_LCASE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:39171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOF8-0002gN-Er for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOF4-0004uG-HW for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJOEz-0002eH-HS for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:18 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:13103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOEz-0002dP-8G for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:13 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NJB000DX1HV87A0@mailout4.w1.samsung.com> for bug-coreutils@gnu.org; Thu, 05 Feb 2015 15:25:07 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-8e-54d389d16c2e Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id CF.DA.07834.1D983D45; Thu, 05 Feb 2015 15:18:41 +0000 (GMT) Received: from [106.109.129.221] by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NJB00C921B6GF50@eusync2.samsung.com>; Thu, 05 Feb 2015 15:21:06 +0000 (GMT) Message-id: <54D38A62.3020202@samsung.com> Date: Thu, 05 Feb 2015 18:21:06 +0300 From: Yury Usishchev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 Content-type: multipart/mixed; boundary=------------030808070700070106020705 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsVy+t/xK7oXOy+HGJzZbGPR2LqG3eLyfm2L ++fOsDgwe7RNM/Po27KKMYApissmJTUnsyy1SN8ugSvj4M2jrAW7uSt+r7vF3sC4gbOLkZND QsBE4vn/KcwQtpjEhXvr2boYuTiEBJYySlz7d4wZwvnMKHF94RRWkCpeAS2JhTd2MYHYLAKq EmsXNTCC2GwCehLfVjxlAbFFBSIk5h97zQxRLyjxY/I9sLiIgKTEmgtXgeIcHMwCaRIzuh1A wsICNhJrfj4HK2EW8JGYeXAS6wRG3llIumchSUHYZhLzNj9khrDlJba/nQNlm0t8uDqdCVPc UWJz2wqmBYzsqxhFU0uTC4qT0nMN9YoTc4tL89L1kvNzNzFCgvbLDsbFx6wOMQpwMCrx8H6I vxwixJpYVlyZe4hRBWjOow2rLzBKseTl56UqifDeaQZK86YkVlalFuXHF5XmpBYfYmTi4JRq YJyv4t5kefbxlN0SrIZzu2c063d53e11mDRN1G3PW8l9l/Ufxf1PKr0rskUlkf1S/ME6R+tn h6pzDKcq2PzP8Zt3es7C00+NUqOYZ3cd/GFTxhso0CvWZ1vC8qLwlMv/n4x37l05c36lXJLq A58p+7Rzcj72HT6yxmAbX9KNf398S2dGLn4RX6rEUpyRaKjFXFScCAC4ERs0RAIAAA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -5.0 (-----) X-Mailman-Approved-At: Thu, 05 Feb 2015 11:52:05 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is a multi-part message in MIME format. --------------030808070700070106020705 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello! We tried to build coreutils with address sanitizer enabled and encountered an error: GEN src/primes.h ==12657== ERROR: AddressSanitizer: heap-buffer-overflow This can be reproduced on git master using gcc-4.8 or gcc-4.9 by git clone export CFLAGS="-fsanitize=address" ./bootstrap ./configure make and is caused by line src/make-prime-list.c:214: while (i < size && sieve[++i] == 0) When 'i' reaches 'size-1' it gets incremented and then (unallocated)memory is accessed. I attached patch that can fix this issue. -- BR, Yury Usishchev --------------030808070700070106020705 Content-Type: text/x-diff; name="asan_prime_fix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="asan_prime_fix.diff" diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 4ec01cf..d293e50 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -195,8 +195,8 @@ main (int argc, char **argv) size = (limit-1)/2; /* sieve[i] represents 3+2*i */ - sieve = xalloc (size); - memset (sieve, 1, size); + sieve = xalloc (size+1); + memset (sieve, 1, size+1); prime_list = xalloc (size * sizeof (*prime_list)); nprimes = 0; --------------030808070700070106020705-- From unknown Wed Aug 20 03:37:31 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Yury Usishchev Subject: bug#19784: closed (Re: bug#19784: build fails on make-prime-list when asan is enabled) Message-ID: References: <54D3B12A.7030900@draigBrady.com> <54D38A62.3020202@samsung.com> X-Gnu-PR-Message: they-closed 19784 X-Gnu-PR-Package: coreutils Reply-To: 19784@debbugs.gnu.org Date: Thu, 05 Feb 2015 18:07:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1423159622-24147-1" This is a multi-part message in MIME format... ------------=_1423159622-24147-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #19784: build fails on make-prime-list when asan is enabled which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 19784@debbugs.gnu.org. --=20 19784: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D19784 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1423159622-24147-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 19784-done) by debbugs.gnu.org; 5 Feb 2015 18:06:43 +0000 Received: from localhost ([127.0.0.1]:34974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJQp8-0006Gx-UV for submit@debbugs.gnu.org; Thu, 05 Feb 2015 13:06:43 -0500 Received: from mail2.vodafone.ie ([213.233.128.44]:27099) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJQp7-0006Gk-Nf for 19784-done@debbugs.gnu.org; Thu, 05 Feb 2015 13:06:42 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AicFANOw01RtTD0E/2dsb2JhbABagwaELMJvgk8CgSdDAQEBAQF9hA0BBSNWEAsNAQoCAgUWCwICCQMCAQIBRQYBDAEHAQGILQHAUIVpkEABAQEBAQEEAQEBAQEBHIEhjlcHgmiBQQEEmVuFPohYgz4ig24+gnMBAQE Received: from unknown (HELO localhost.localdomain) ([109.76.61.4]) by mail2.vodafone.ie with ESMTP; 05 Feb 2015 18:06:34 +0000 Message-ID: <54D3B12A.7030900@draigBrady.com> Date: Thu, 05 Feb 2015 18:06:34 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Yury Usishchev , 19784-done@debbugs.gnu.org Subject: Re: bug#19784: build fails on make-prime-list when asan is enabled References: <54D38A62.3020202@samsung.com> In-Reply-To: <54D38A62.3020202@samsung.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 19784-done Cc: Vyacheslav Barinov , =?UTF-8?B?67CV7LCs7Zi4?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 05/02/15 15:21, Yury Usishchev wrote: > Hello! > > We tried to build coreutils with address sanitizer enabled and > encountered an error: > > GEN src/primes.h > ==12657== ERROR: AddressSanitizer: heap-buffer-overflow > > This can be reproduced on git master using gcc-4.8 or gcc-4.9 by > git clone > export CFLAGS="-fsanitize=address" > ./bootstrap > ./configure > make > > and is caused by line > src/make-prime-list.c:214: while (i < size && sieve[++i] == 0) > > When 'i' reaches 'size-1' it gets incremented and then > (unallocated)memory is accessed. > > I attached patch that can fix this issue. Oh nice one. That was not rerun when I ran my checks. The released tools (still) pass with -fsanitize=address. How about this fix instead? I'll push in your name if you're ok with it. diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 68c972a..69b91e8 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -211,7 +211,7 @@ main (int argc, char **argv) for (j = (p*p - 3)/2; j < size; j+= p) sieve[j] = 0; - while (i < size && sieve[++i] == 0) + while (++i < size && sieve[i] == 0) ; } ------------=_1423159622-24147-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 5 Feb 2015 16:52:07 +0000 Received: from localhost ([127.0.0.1]:34931 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJPev-00038I-VK for submit@debbugs.gnu.org; Thu, 05 Feb 2015 11:52:06 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40725) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJOFF-0000xQ-QD for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJOF8-0002gR-Hg for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:23 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_MANY_HDRS_LCASE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:39171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOF8-0002gN-Er for submit@debbugs.gnu.org; Thu, 05 Feb 2015 10:21:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOF4-0004uG-HW for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJOEz-0002eH-HS for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:18 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:13103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJOEz-0002dP-8G for bug-coreutils@gnu.org; Thu, 05 Feb 2015 10:21:13 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NJB000DX1HV87A0@mailout4.w1.samsung.com> for bug-coreutils@gnu.org; Thu, 05 Feb 2015 15:25:07 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-8e-54d389d16c2e Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id CF.DA.07834.1D983D45; Thu, 05 Feb 2015 15:18:41 +0000 (GMT) Received: from [106.109.129.221] by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NJB00C921B6GF50@eusync2.samsung.com>; Thu, 05 Feb 2015 15:21:06 +0000 (GMT) Message-id: <54D38A62.3020202@samsung.com> Date: Thu, 05 Feb 2015 18:21:06 +0300 From: Yury Usishchev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 To: bug-coreutils@gnu.org Subject: build fails on make-prime-list when asan is enabled Content-type: multipart/mixed; boundary=------------030808070700070106020705 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsVy+t/xK7oXOy+HGJzZbGPR2LqG3eLyfm2L ++fOsDgwe7RNM/Po27KKMYApissmJTUnsyy1SN8ugSvj4M2jrAW7uSt+r7vF3sC4gbOLkZND QsBE4vn/KcwQtpjEhXvr2boYuTiEBJYySlz7d4wZwvnMKHF94RRWkCpeAS2JhTd2MYHYLAKq EmsXNTCC2GwCehLfVjxlAbFFBSIk5h97zQxRLyjxY/I9sLiIgKTEmgtXgeIcHMwCaRIzuh1A wsICNhJrfj4HK2EW8JGYeXAS6wRG3llIumchSUHYZhLzNj9khrDlJba/nQNlm0t8uDqdCVPc UWJz2wqmBYzsqxhFU0uTC4qT0nMN9YoTc4tL89L1kvNzNzFCgvbLDsbFx6wOMQpwMCrx8H6I vxwixJpYVlyZe4hRBWjOow2rLzBKseTl56UqifDeaQZK86YkVlalFuXHF5XmpBYfYmTi4JRq YJyv4t5kefbxlN0SrIZzu2c063d53e11mDRN1G3PW8l9l/Ufxf1PKr0rskUlkf1S/ME6R+tn h6pzDKcq2PzP8Zt3es7C00+NUqOYZ3cd/GFTxhso0CvWZ1vC8qLwlMv/n4x37l05c36lXJLq A58p+7Rzcj72HT6yxmAbX9KNf398S2dGLn4RX6rEUpyRaKjFXFScCAC4ERs0RAIAAA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 05 Feb 2015 11:52:05 -0500 Cc: Vyacheslav Barinov , =?UTF-8?B?67CV7LCs7Zi4?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is a multi-part message in MIME format. --------------030808070700070106020705 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello! We tried to build coreutils with address sanitizer enabled and encountered an error: GEN src/primes.h ==12657== ERROR: AddressSanitizer: heap-buffer-overflow This can be reproduced on git master using gcc-4.8 or gcc-4.9 by git clone export CFLAGS="-fsanitize=address" ./bootstrap ./configure make and is caused by line src/make-prime-list.c:214: while (i < size && sieve[++i] == 0) When 'i' reaches 'size-1' it gets incremented and then (unallocated)memory is accessed. I attached patch that can fix this issue. -- BR, Yury Usishchev --------------030808070700070106020705 Content-Type: text/x-diff; name="asan_prime_fix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="asan_prime_fix.diff" diff --git a/src/make-prime-list.c b/src/make-prime-list.c index 4ec01cf..d293e50 100644 --- a/src/make-prime-list.c +++ b/src/make-prime-list.c @@ -195,8 +195,8 @@ main (int argc, char **argv) size = (limit-1)/2; /* sieve[i] represents 3+2*i */ - sieve = xalloc (size); - memset (sieve, 1, size); + sieve = xalloc (size+1); + memset (sieve, 1, size+1); prime_list = xalloc (size * sizeof (*prime_list)); nprimes = 0; --------------030808070700070106020705-- ------------=_1423159622-24147-1-- From unknown Wed Aug 20 03:37:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#19784: build fails on make-prime-list when asan is enabled Resent-From: Yury Usishchev Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 05 Feb 2015 19:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19784 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady , 19784@debbugs.gnu.org Cc: Vyacheslav Barinov , =?UTF-8?Q?=EB=B0=95=EC=B0=AC=ED=98=B8?= Received: via spool by 19784-submit@debbugs.gnu.org id=B19784.14231646054381 (code B ref 19784); Thu, 05 Feb 2015 19:31:02 +0000 Received: (at 19784) by debbugs.gnu.org; 5 Feb 2015 19:30:05 +0000 Received: from localhost ([127.0.0.1]:35014 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJS7n-00018N-U5 for submit@debbugs.gnu.org; Thu, 05 Feb 2015 14:30:04 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:26116) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YJS7k-00017b-LT for 19784@debbugs.gnu.org; Thu, 05 Feb 2015 14:30:02 -0500 MIME-version: 1.0 Content-type: text/plain; charset=utf-8; format=flowed Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NJB00EUZD0J2R00@mailout2.w1.samsung.com> for 19784@debbugs.gnu.org; Thu, 05 Feb 2015 19:33:55 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-01-54d3c41fb987 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 2A.1F.07834.F14C3D45; Thu, 05 Feb 2015 19:27:27 +0000 (GMT) Content-transfer-encoding: 8BIT Received: from [106.109.129.221] by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NJB00DE6CTRJ250@eusync1.samsung.com>; Thu, 05 Feb 2015 19:29:52 +0000 (GMT) Message-id: <54D3C4AF.1070204@samsung.com> Date: Thu, 05 Feb 2015 22:29:51 +0300 From: Yury Usishchev User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 References: <54D38A62.3020202@samsung.com> <54D3B12A.7030900@draigBrady.com> In-reply-to: <54D3B12A.7030900@draigBrady.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrALMWRmVeSWpSXmKPExsVy+t/xy7ryRy6HGOx9r2CxY0kbu8Xl/doW 6+aaWtw/d4bFgcXj4qR9zB63praze/RtWcUYwBzFZZOSmpNZllqkb5fAlXFo91TWgg7uirMv 2RoYN3N0MXJySAiYSOy/eoAZwhaTuHBvPVsXIxeHkMBSRol1rxezgiR4BQQlfky+x9LFyMHB LCAvceRSNkiYWcBM4svLw6wQ9Z8ZJRZ/BGkGqdeSmL1nEyOIzSKgKvH8xwewOJuAnsS3FU9Z QGxRgQiJ+cdegy0WEfCT6Jk4jxVifprEjG4HkLCwgLfEw6N/wFqFBHwk2n+8BDuHE2jM1Fk9 LBMYBWYhuW4WwnWzkFy3gJF5FaNoamlyQXFSeq6hXnFibnFpXrpecn7uJkZIqH7Zwbj4mNUh RgEORiUe3g/xl0OEWBPLiitzDzFKcDArifDeaQYK8aYkVlalFuXHF5XmpBYfYmTi4JRqYJye a+BresPbMMv0gNGnummHn2ws8s64cD/p3JaKydu2Pk0UPiwf9aHztHFL1sO9wTWr3y79VWm3 ZKXkdgWlxKAdaWHc1hKn5LZ/7P+fcm6/XUC1/udGkf91bo/4+D/4KHRMj19gFFNwaGqsj09I boaPUsX/t0Hn80zT98T906jtYJ+9SWb9FSWW4oxEQy3mouJEAClMJ0MzAgAA X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) On 02/05/2015 09:06 PM, Pádraig Brady wrote: > On 05/02/15 15:21, Yury Usishchev wrote: >> Hello! >> >> We tried to build coreutils with address sanitizer enabled and >> encountered an error: >> >> GEN src/primes.h >> ==12657== ERROR: AddressSanitizer: heap-buffer-overflow >> >> This can be reproduced on git master using gcc-4.8 or gcc-4.9 by >> git clone >> export CFLAGS="-fsanitize=address" >> ./bootstrap >> ./configure >> make >> >> and is caused by line >> src/make-prime-list.c:214: while (i < size && sieve[++i] == 0) >> >> When 'i' reaches 'size-1' it gets incremented and then >> (unallocated)memory is accessed. >> >> I attached patch that can fix this issue. > Oh nice one. That was not rerun when I ran my checks. > The released tools (still) pass with -fsanitize=address. > > How about this fix instead? I'll push in your name if > you're ok with it. > > diff --git a/src/make-prime-list.c b/src/make-prime-list.c > index 68c972a..69b91e8 100644 > --- a/src/make-prime-list.c > +++ b/src/make-prime-list.c > @@ -211,7 +211,7 @@ main (int argc, char **argv) > for (j = (p*p - 3)/2; j < size; j+= p) > sieve[j] = 0; > > - while (i < size && sieve[++i] == 0) > + while (++i < size && sieve[i] == 0) > ; > } Thank you for quick reply. Yes, this patch looks much better. -- BR, Yury Usishchev