public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/1952] New: time() returns incorrect value when given bad address
@ 2005-11-30 15:50 michael dot kerrisk at gmx dot net
2005-11-30 16:18 ` [Bug libc/1952] " jakub at redhat dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: michael dot kerrisk at gmx dot net @ 2005-11-30 15:50 UTC (permalink / raw)
To: glibc-bugs
When the program below is run on Linux/x86, the following output
is produced:
After time(): t=-14, errno=0
After syscall(SYS_time): t=-1, errno=14
In the first line, the reported return value from time() should be
-1, with errno set to EFAULT (14). Instead, the call returns -14.
Could this be a configuration problem in
sysdeps/unix/sysv/linux/i386/syscalls.list?
Cheers,
Michael
==========
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <time.h>
#define VAL 1000
int main() {
time_t t;
t = time((time_t *)VAL);
printf("After time(): t=%ld, errno=%d\n", (long) t, errno);
t = syscall(SYS_time, (time_t *)VAL);
printf("After syscall(SYS_time): t=%ld, errno=%d\n", (long) t, errno);
return 0;
}
--
Summary: time() returns incorrect value when given bad address
Product: glibc
Version: 2.3.5
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: michael dot kerrisk at gmx dot net
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=1952
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libc/1952] time() returns incorrect value when given bad address
2005-11-30 15:50 [Bug libc/1952] New: time() returns incorrect value when given bad address michael dot kerrisk at gmx dot net
@ 2005-11-30 16:18 ` jakub at redhat dot com
2005-11-30 16:31 ` michael dot kerrisk at gmx dot net
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: jakub at redhat dot com @ 2005-11-30 16:18 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From jakub at redhat dot com 2005-11-30 16:18 -------
time is marked with E, i.e. not returning error (which I'd say matches
POSIX which doesn't define any errors for time). By passing an invalid
address to the function you reach undefined behaviour territory and all answers
are fine in that case.
--
http://sourceware.org/bugzilla/show_bug.cgi?id=1952
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libc/1952] time() returns incorrect value when given bad address
2005-11-30 15:50 [Bug libc/1952] New: time() returns incorrect value when given bad address michael dot kerrisk at gmx dot net
2005-11-30 16:18 ` [Bug libc/1952] " jakub at redhat dot com
@ 2005-11-30 16:31 ` michael dot kerrisk at gmx dot net
2005-12-20 7:50 ` drepper at redhat dot com
2005-12-20 8:18 ` michael dot kerrisk at gmx dot net
3 siblings, 0 replies; 5+ messages in thread
From: michael dot kerrisk at gmx dot net @ 2005-11-30 16:31 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From michael dot kerrisk at gmx dot net 2005-11-30 16:31 -------
Subject: Re: time() returns incorrect value when given bad address
> time is marked with E, i.e. not returning error (which I'd say matches
> POSIX which doesn't define any errors for time). By passing an invalid
> address to the function you reach undefined behaviour territory and all
> answers are fine in that case.
Hi Jakub
Thanks for your quick reply.
POSIX does not define any errno values for time(), but nevertheless
says:
Upon successful completion, time( ) shall return the value of
time. Otherwise, (time_t)−1 shall be returned.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In my book, that means that time() should reasonably return -1
here.
The POSIX.1 "No errors are defined" means
that error values returned by a function or stored into a
variable accessed through the symbol errno, if any, depend
on the implementation.
This does not (in my reading) mean that no error indication
(i.e., -1 in this case) should be returned.
Note also that glibc is thwarting the underlying system call, which
does actually return -1 for this case (as my program demonstrates).
Cheers,
Michael
--
http://sourceware.org/bugzilla/show_bug.cgi?id=1952
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libc/1952] time() returns incorrect value when given bad address
2005-11-30 15:50 [Bug libc/1952] New: time() returns incorrect value when given bad address michael dot kerrisk at gmx dot net
2005-11-30 16:18 ` [Bug libc/1952] " jakub at redhat dot com
2005-11-30 16:31 ` michael dot kerrisk at gmx dot net
@ 2005-12-20 7:50 ` drepper at redhat dot com
2005-12-20 8:18 ` michael dot kerrisk at gmx dot net
3 siblings, 0 replies; 5+ messages in thread
From: drepper at redhat dot com @ 2005-12-20 7:50 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2005-12-20 07:50 -------
I've added a new implementation which will simply crash for all invalid pointers.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://sourceware.org/bugzilla/show_bug.cgi?id=1952
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libc/1952] time() returns incorrect value when given bad address
2005-11-30 15:50 [Bug libc/1952] New: time() returns incorrect value when given bad address michael dot kerrisk at gmx dot net
` (2 preceding siblings ...)
2005-12-20 7:50 ` drepper at redhat dot com
@ 2005-12-20 8:18 ` michael dot kerrisk at gmx dot net
3 siblings, 0 replies; 5+ messages in thread
From: michael dot kerrisk at gmx dot net @ 2005-12-20 8:18 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From michael dot kerrisk at gmx dot net 2005-12-20 08:18 -------
Subject: Re: time() returns incorrect value when given bad address
>
> ------- Additional Comments From drepper at redhat dot com 2005-12-20
> 07:50 -------
> I've added a new implementation which will simply crash for
> all invalid pointers.
Good! Thanks.
--
http://sourceware.org/bugzilla/show_bug.cgi?id=1952
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-12-20 8:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-30 15:50 [Bug libc/1952] New: time() returns incorrect value when given bad address michael dot kerrisk at gmx dot net
2005-11-30 16:18 ` [Bug libc/1952] " jakub at redhat dot com
2005-11-30 16:31 ` michael dot kerrisk at gmx dot net
2005-12-20 7:50 ` drepper at redhat dot com
2005-12-20 8:18 ` michael dot kerrisk at gmx dot net
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).