#776891 libc6-dev: time_t time(time_t *t) behavior does not conform to specification

Package:
libc6-dev
Source:
glibc
Description:
GNU C Library: Development Libraries and Header Files
Submitter:
Jesse Maes
Date:
2015-02-02 22:18:05 UTC
Severity:
normal
#776891#5
Date:
2015-02-02 22:09:04 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

   I was writing some short simple example code to demonstrate error handling in
   a UNIX environment. I attempted to purposely produce an error by calling the
   `time` function with a bad parameter.


   * What exactly did you do (or not do) that was effective (or
     ineffective)?

   See: http://stackoverflow.com/questions/28286290/linux-system-call-time-is-returning-time-t-14-on-error

   I compiled a program with gcc containing this simple code snippet and ran it:

    {
        time_t *ptr = (time_t *) 0xabad1dea;
        time_t secs = time(ptr);

        if (secs == ((time_t) -1)) /* Not caught */
            exit(EXIT_FAILURE);

        printf("Number of seconds since the Epoch:        %lld\n", secs);
        printf("It should return ((time_t) -1) on error:  %lld\n", (time_t) -1);
        perror("Error Message:");
        secs = *ptr; /* This *does* segfault */
    }


   * What was the outcome of this action?

   The error condition was not caught. `time` returned -14 when passed
   an out-of-bounds address and did not set `errno`.


   * What outcome did you expect instead?

   The manual (`man 2 time`), POSIX, and the C standard lead me to believe that
   time should return -1 and set errno to EFAULT (14). The of the function in
   this version of libc is incorrect. I thought someone should know, since this
   is sort of a confusing glibc bug.