Bug 14250 - [ia64] ia64 makecontext.c writes to stderr and it should not.
Summary: [ia64] ia64 makecontext.c writes to stderr and it should not.
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2012-06-15 14:49 UTC by Carlos O'Donell
Modified: 2014-06-25 10:54 UTC (History)
5 users (show)

See Also:
Host: ia64-linux-gnu
Target: ia64-linux-gnu
Build: ia64-linux-gnu
Last reconfirmed:
fweimer: security-


Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2012-06-15 14:49:26 UTC
The implementation of makecontext() for ia64 (ports/sysdeps/unix/sysv/linux/ia64/makecontext.c) writes to stderr if there are more than 8 arguments.

The function should not write to stderr, see bug #13983 for some background. Instead the function should set errno and return.

Unfortunately POSIX doesn't seem to dictate any errno for makecontext(), almost as if it should never fail. This is IMO an oversight, we should return EINVAL when > 8 arguments. At least IBM's XL C runtime returns EINVAL with invalid argc.

We must strive for a high QoI and avoid arbitrarily writing to stderr.
Comment 1 Mike Frysinger 2012-06-16 03:56:17 UTC
i did see this failure, but was trying to figure out how to make it work.  i'm not really worried about the stderr write ... the fact that it calls exit() seems like a much worse violation.

i could have it setup the context in such a way that when it calls setcontext, that function would return an error ...
Comment 2 Carlos O'Donell 2012-06-18 14:19:07 UTC

I didn't notice the call to exit(). Calling exit() is definitely the wrong thing to do in this context. 

Returning EINVAL when argc > 8 would fix both of these problems.

I wonder if you couldn't somehow macro-ize this to fail at build time if argc was greater than 8?
Comment 3 Rich Felker 2012-06-18 21:41:54 UTC
It's possible to make it fail at compile-time using macros if the function is called directly, but this won't catch all cases, such as calls to makecontext via a function pointer or when the caller prototypes the function without including the header. The test at runtime is really necessary.