Menu

#433 Drop getpass() or replace with termios

version-cvs
open
nobody
None
5
2017-04-26
2016-03-14
No

This function is obsolete. Do not use it. If you want to read input without terminal echoing enabled, see the description of the ECHO flag in termios(3).

Let's ditch it!

Discussion

  • Zdenek Styblik

    Zdenek Styblik - 2016-04-21
    • Group: version-1.8.17 --> version-cvs
     
  • Jesper Schmitz Mouridsen

    and consider readpassphrase on FreeBSD. getpass segfaults. So you have to specify on commandline with -P.

     
  • Andrew Daugherity

    I think #436 was closed prematurely, as it still segfaults after entering a password on macOS, even though std=gnu99 is now used. I tracked that down to the getpass() prototype not being defined -- turns out on macOS X's <unistd.h>, getpass() is defined (or not) based on the value of _POSIX_C_SOURCE, which is in turn set based on _XOPEN_SOURCE. _BSD_SOURCE does not matter here, unlike e.g FreeBSD & OpenBSD which use something like #if (defined _BSD_SOURCE) || (_XOPEN_SOURCE <= 500).</unistd.h>

    Compiler warning about getpass():

    ipmi_main.c:468:15: warning: implicit declaration of function 'getpass' is invalid in C99 [-Wimplicit-function-declaration]
                            tmp_pass = getpass("Password: ");
                                       ^
    ipmi_main.c:468:13: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                            tmp_pass = getpass("Password: ");
                                     ^ ~~~~~~~~~~~~~~~~~~~~~
    

    After changing the define to #define _XOPEN_SOURCE 500, the segfault is gone. There is now a compiler warning about getpass being deprecated, but that's known (and is in fact the whole point of this ticket!).

    Furthermore, the #define of _BSD_SOURCE in this file is not correct. This long conditional is copied from the getpass(3) man page (glibc version), but what is listed is the test in glibc's <unistd.h>, not what should be defined in your file, which should (for glibc) either define _BSD_SOURCE or define _XOPEN_SOURCE to 500 before including <unistd.h> to include getpass(); defining _XOPEN_SOURCE to >= 600 will not include getpass().</unistd.h></unistd.h>

    If it's left at all, it should just be #define _BSD_SOURCE, but having #define _XOPEN_SOURCE 500 should be sufficient.

    In summary: setting _XOPEN_SOURCE to 700 at the top of lib/ipmi_main.c is incorrect, as it causes the getpass() prototype to not be used. Changing it to 500 causes the segfault to go away. The _BSD_SOURCE define is not needed. Simple patch attached.

     

Log in to post a comment.

MongoDB Logo MongoDB