[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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



Package: libc6-dev
Version: 2.13-38+deb7u3
Severity: normal
Tags: upstream

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.


-- System Information:
Debian Release: 7.6
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable'), (100, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages libc6-dev depends on:
ii  libc-dev-bin    2.13-38+deb7u3
ii  libc6           2.13-38+deb7u3
ii  linux-libc-dev  3.2.60-1+deb7u3

Versions of packages libc6-dev recommends:
ii  gcc [c-compiler]      4:4.7.2-1
ii  gcc-4.6 [c-compiler]  4.6.3-14
ii  gcc-4.7 [c-compiler]  4.7.2-5

Versions of packages libc6-dev suggests:
pn  glibc-doc     <none>
ii  manpages-dev  3.44-1

-- no debconf information


Reply to: