public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Joan Bruguera <joanbrugueram@gmail.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH] misc: Fix rare fortify crash on wchar funcs. [BZ 29030]
Date: Mon, 18 Apr 2022 10:45:33 +0530	[thread overview]
Message-ID: <bd4fc536-21f3-6254-1492-c7c9e20b3d30@gotplt.org> (raw)
In-Reply-To: <56718a77-f902-9fc3-27a0-8b1a27698794@gotplt.org>

On 18/04/2022 10:14, Siddhesh Poyarekar wrote:
>>         cp = "A";
>>         if (mbstowcs (wenough, cp, 10) != 1
>>         || wcscmp (wenough, L"A") != 0)
>> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
>> index 44d3826bca..b8419e7e6c 100644
>> --- a/misc/sys/cdefs.h
>> +++ b/misc/sys/cdefs.h
>> @@ -156,14 +156,14 @@
>>      variants.  These conditions should get evaluated to constant and 
>> optimized
>>      away.  */
>> -#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / 
>> (__s))
>> +#define __glibc_safe_len_cond(__l, __s, __osz) \
>> +  ((__osz) == (size_t) -1 || ((__l) <= (__osz) / (__s)))
> 
> This should go...
> 
>>   #define __glibc_unsigned_or_positive(__l) \
>>     ((__typeof (__l)) 0 < (__typeof (__l)) -1                      \
>>      || (__builtin_constant_p (__l) && (__l) > 0))
>>   /* Length is known to be safe at compile time if the __L * __S <= 
>> __OBJSZ
>> -   condition can be folded to a constant and if it is true.  The -1 
>> check is
>> -   redundant because since it implies that __glibc_safe_len_cond is 
>> true.  */
>> +   condition can be folded to a constant and if it is true, or 
>> unknown (-1) */
>>   #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
> 
> here since the above macro is "safe length condition" and this one is 
> "safe or unknown length", so the unknown length check ideally belongs here.

Sorry I missed another note, please use __SIZE_TYPE__ instead of size_t 
to avoid having to include stddef.h.

Thanks,
Siddhesh

  reply	other threads:[~2022-04-18  5:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 17:49 Joan Bruguera
2022-04-18  4:44 ` Siddhesh Poyarekar
2022-04-18  5:15   ` Siddhesh Poyarekar [this message]
2022-04-25 12:04 ` [committed] " Siddhesh Poyarekar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd4fc536-21f3-6254-1492-c7c9e20b3d30@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=joanbrugueram@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).