Bug 31286 - glibc 2.36: Aliasing violation in libio/iovdprintf.c before refactor to internal buffers
Summary: glibc 2.36: Aliasing violation in libio/iovdprintf.c before refactor to inter...
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-24 04:27 UTC by Carlos O'Donell
Modified: 2024-02-15 18:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2024-01-24 04:27:39 UTC
In libio/iovdprintf.c in glibc 2.36 (before 8ece45e4f586abd212d1c02d74d38ef681a45600 and the conversion to internal buffers):

 58 
 59   _IO_FINISH (&tmpfil.file);
 60 

The macro casts from the first member to the outer containing struct.

 92 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
 93    violation in case THIS has a different pointer type.  */
 94 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
 95   (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
 96                                        + offsetof(TYPE, MEMBER)))

This works but some downstream pointer provenance checking tooling raises this as an error.

It really should have been '_IO_FINISH (&tmpfil)'
Comment 1 Sam James 2024-01-25 10:47:20 UTC
> This works but some downstream pointer provenance checking tooling raises
> this as an error.

(Out of interest, what tooling?)
Comment 2 Carlos O'Donell 2024-01-25 12:32:07 UTC
(In reply to Sam James from comment #1)
> > This works but some downstream pointer provenance checking tooling raises
> > this as an error.
> 
> (Out of interest, what tooling?)

Coverity.
Comment 3 Florian Weimer 2024-01-25 16:52:22 UTC
_IO_new_fdopen has a similar problem:

      off64_t new_pos = _IO_SYSSEEK (&new_f->fp.file, 0, _IO_seek_end);
Comment 4 Sam James 2024-02-15 18:16:08 UTC
-Wstrict-aliasing=2 has many complaints as well with gcc version 14.0.1 20240214 (experimental) and -O3. I don't think all of them are real problems, but at a glance, at least some of them are.