News for hackers. Stuff that matters.
Re:A brief history of one line fixes by _pmf_ on Saturday March 01, 2014 @03:55PM (#7326059)
> How is this possible? Does nobody use a compiler that warns about comparisons always being false?

External symbols are resolved at link time; as far as the compiler is concerned, setuid might be a symbol declared as __weak.

I don't particularly like the snide remarks towards the maintainers of these libraries.

Re:A brief history of one line fixes by spc476 on Saturday March 01, 2014 @05:43PM (#7326485)
I ran the following code through GCC:

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>

    int main(void)
    {
      if (getuid() != 0 && geteuid == 0)
      {
        printf("only root\n");
        return 1;
      }
      printf("okay\n");
      return 0;
    }
With just a plain GCC (no options), the code compiled and exhibited the bug (it always printed "okay"). That's to be expected. What was not expected what when I compiled the code with "gcc -ansi -Wall -Wextra -pedantic". NOT ONE ERROR OR WARNING!

How is that happening?

Well, C allows function pointers. Also, in C, a value of 0 used in a pointer context is treated as a NULL pointer. So that one line is seen as:

    if (getuid() != 0 && geteuid == NULL)
Now, let's play compiler. geteuid() is a function and it's defined. So the compiler can generate:

    if (getuid() != 0 && false)
The result of this expression can never be true. But because the call to getuid() could cause side-effects (the prototype for getuid() does not include the GCC extension marking it as a "pure" function) the compiler has to emit a call to the function, but otherwise, it ignores the result since it doesn't matter what the result is. The resultant code is:

    int main(void)
    {
      getuid();
      printf("okay\n");
      return 0;
    }
And thus, it's possible, even with the commonly used "-Wall -Wextra" options to GCC. To detect this, you will also need to add "-Wunreachable-code" (why that isn't included with '-Wall' is a good question).
Re:A brief history of one line fixes by CUViper on Saturday March 01, 2014 @06:49PM (#7326801)
> "gcc -ansi -Wall -Wextra -pedantic". NOT ONE ERROR OR WARNING!

  $ rpm -q gcc
  gcc-4.8.2-7.fc20.x86_64
  $ gcc -ansi -Wall -Wextra -pedantic test.c
  test.c: In function ‘main’:
  test.c:7:36: warning: the comparison will always evaluate as ‘false’ for the address of ‘geteuid’ will never be NULL [-Waddress]
         if (getuid() != 0 && geteuid == 0)
                                      ^
If fact, just -Wall is enough to enable that warning. Maybe the coverage of -Waddress has changed since your version?
Re:A brief history of one line fixes by spc476 on Saturday March 01, 2014 @07:58PM (#7327097)
Could very well be. I am using a slightly older version of GCC.
Re:A brief history of one line fixes by w-m on Saturday March 01, 2014 @06:51PM (#7326815)
huh?

gcc 4.2 -Wall:

  warning: the address of ‘geteuid’ will never be NULL
gcc 4.8 -Wall:

  warning: the comparison will always evaluate as 'false' for the address of 'geteuid' will never be NULL [-Waddress]
       if (getuid() != 0 && geteuid == 0)

Also, as came up in the goto fail discussion, -Wunreachable-code was removed from gcc and doesn't warn on anything.
Re:A brief history of one line fixes by spc476 on Saturday March 01, 2014 @08:03PM (#7327117)
It appears that GCC has changed a bit since that article was originally written (2010). And I'm using a GCC that is a bit old.
Re:A brief history of one line fixes by nkeets on Saturday March 01, 2014 @09:25PM (#7327389)
It appears that you are spreading FUD. In a thread discussing if one line bugs could be written on purpose, it is only fitting to discuss if you demonstrated gcc's failing by using a version older than 4.2 was also on purpose.

By the way, I'm interested to know which version you used.

Re:A brief history of one line fixes by spc476 on Saturday March 01, 2014 @11:06PM (#7327663)
How am I spreading FUD? By using an older version of GCC and reporting what I saw? Should I edit my post to remove all mentions of GCC and just leave how the code is interpreted as is?
Re:A brief history of one line fixes by nkeets on Sunday March 02, 2014 @02:41AM (#7328153)
It has to be before 4.2 (you never said which version you used), which is really old. And you went to all this trouble but never occurred to you that compiler version could be a factor?

Sure it could be an honest mistake, but that's also true for Apple's bug (and the rest).

Re:A brief history of one line fixes by GhotiFish on Saturday March 01, 2014 @04:53PM (#7326304)
I suspect the author is parodying the reaction towards apples mistake, and bares these maintainers no ill will.