This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback



On 08/10/2019 15:52, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> +#define DP_MEMBER(src, type, member)			     \
>> +    (__typeof__((type){0}.member) *)			     \
>> +      memcpy (&((__typeof__((type){0}.member)){0}),          \
>> +	      ((char *)(src) + offsetof (type, member)),     \
>> +	      sizeof ((type){0}.member))
> 
> Please add a comment that this is used to avoid an aliasing violation.

Ack.

> 
>> +      memcpy (((char *)(dp) + offsetof (struct dirent64, d_ino)),
>> +	      DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> +	      sizeof ((struct dirent64){0}.d_ino));
>> +      memcpy (((char *)(dp) + offsetof (struct dirent64, d_off)),
>> +	      DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> +	      sizeof ((struct dirent64){0}.d_ino));
>> +      memcpy (&last_offset,
>> +	      DP_MEMBER (kdp, struct kernel_dirent, d_off),
>> +	      sizeof (last_offset));
> 
> I think you should be able to use:
> 
>    last_offset = *DP_MEMBER (kdp, struct kernel_dirent, d_off);
> 
> last_offset has the correct type.

Ack.

> 
>> +      memcpy (DP_MEMBER (dp, struct dirent64, d_reclen), &new_reclen,
>> +	      sizeof ((struct dirent64){0}.d_reclen));
> 
> That looks wrong.  DP_MEMBER (dp, struct dirent64, d_reclen) is a
> temporary object, so the outer memcpy is dead.

Sigh, indeed. I changed to:

   memcpy (((char *)(dp) + offsetof (struct dirent64, d_reclen)),
           &new_reclen, sizeof ((struct dirent64){0}.d_reclen));

> 
> Thanks,
> Florian
> 

I hope I got this right this time...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]