GNU bug report logs - #19784
build fails on make-prime-list when asan is enabled

Previous Next

Package: coreutils;

Reported by: Yury Usishchev <y.usishchev <at> samsung.com>

Date: Thu, 5 Feb 2015 16:53:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19784 in the body.
You can then email your comments to 19784 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#19784; Package coreutils. (Thu, 05 Feb 2015 16:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yury Usishchev <y.usishchev <at> samsung.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Thu, 05 Feb 2015 16:53:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yury Usishchev <y.usishchev <at> samsung.com>
To: bug-coreutils <at> gnu.org
Cc: Vyacheslav Barinov <v.barinov <at> samsung.com>,
 박찬호 <chanho61.park <at> samsung.com>
Subject: build fails on make-prime-list when asan is enabled
Date: Thu, 05 Feb 2015 18:21:06 +0300
[Message part 1 (text/plain, inline)]
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

[asan_prime_fix.diff (text/x-diff, attachment)]

Reply sent to Pádraig Brady <P <at> draigBrady.com>:
You have taken responsibility. (Thu, 05 Feb 2015 18:07:02 GMT) Full text and rfc822 format available.

Notification sent to Yury Usishchev <y.usishchev <at> samsung.com>:
bug acknowledged by developer. (Thu, 05 Feb 2015 18:07:02 GMT) Full text and rfc822 format available.

Message #10 received at 19784-done <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Yury Usishchev <y.usishchev <at> samsung.com>, 19784-done <at> debbugs.gnu.org
Cc: Vyacheslav Barinov <v.barinov <at> samsung.com>,
 박찬호 <chanho61.park <at> samsung.com>
Subject: Re: bug#19784: build fails on make-prime-list when asan is enabled
Date: Thu, 05 Feb 2015 18:06:34 +0000
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)
         ;
     }





Information forwarded to bug-coreutils <at> gnu.org:
bug#19784; Package coreutils. (Thu, 05 Feb 2015 19:31:02 GMT) Full text and rfc822 format available.

Message #13 received at 19784 <at> debbugs.gnu.org (full text, mbox):

From: Yury Usishchev <y.usishchev <at> samsung.com>
To: Pádraig Brady <P <at> draigBrady.com>, 19784 <at> debbugs.gnu.org
Cc: Vyacheslav Barinov <v.barinov <at> samsung.com>,
 박찬호 <chanho61.park <at> samsung.com>
Subject: Re: bug#19784: build fails on make-prime-list when asan is enabled
Date: Thu, 05 Feb 2015 22:29:51 +0300
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





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 06 Mar 2015 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.