bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Openat without die


From: Eric Blake
Subject: Re: Openat without die
Date: Tue, 11 Jan 2011 12:03:39 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7

On 01/11/2011 11:58 AM, Eric Blake wrote:
>>  char *
>>  openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
>>  {
>> @@ -98,7 +99,13 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, 
>> char const *file)
>>    else
>>      {
>>        size_t bufsize = PROC_SELF_FD_NAME_SIZE_BOUND (strlen (file));
>> -      char *result = (bufsize < OPENAT_BUFFER_SIZE ? buf : xmalloc 
>> (bufsize));
>> +      char *result = buf;
>> +      if (OPENAT_BUFFER_SIZE < bufsize)
>> +        {
>> +          result = malloc (bufsize);
>> +          if (! result)
>> +            return NULL;
> 
> Either we must depend on malloc-posix, or you need to force errno=ENOMEM
> here rather than relying on malloc() to do it.

Correction - due to how openat_proc_name is used, we _don't_ need
malloc-posix, because you didn't change things to promise a sane errno.
 Since we _always_ fallback to the fchdir method if this failed without
ever inspecting errno, the caller never needs to know that we had an
intermediate ENOMEM situation, and we can get by without worrying
whether malloc set errno.

But you should still drop the xmalloc dependency from the module
description.

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]