Possible truncation of the cookie in telldir/seekdir.

Marcin Mielniczuk marcin@golem.network
Fri Aug 30 10:44:00 GMT 2019


Hi,

On 32-bit OSes readdir64 will internally call the getdents64. There the
value for dirent64::d_off will be taken from unsigned long
linux_dirent::d_off, which is off64_t (the same as int64_t) and assigned
to __dirstream::filepos, which is off_t. On 32-bit systems, off_t is the
same as int32_t and long. Therefore, telldir will return a truncated
value. This can be reproduced, for instance, when cross-compiling to
arm-unknown-linux-gnueabi.

This means that (1) the value returned in dirent64::d_off may not match
the one returned by telldir (2) if we use seekdir with the value from
dirent64::d_off, a silent lossy conversion may happen and the stream may
be incorrectly seeked. According to POSIX, telldir & seekdir should use
a long, so this can't be fixed by simply using off64_t everywhere.

Is this a known issue? I see that IBM "circumvented" this problem in the
AIX libc by adding seekdir64 and telldir64.
Btw. on my system there's no manpage describing readdir64. Is this intended?

Regards,
Marcin



More information about the Libc-help mailing list