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).
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>
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.
and consider readpassphrase on FreeBSD. getpass segfaults. So you have to specify on commandline with -P.
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_SOURCEdoes 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():
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_SOURCEor define_XOPEN_SOURCEto 500 before including <unistd.h> to include getpass(); defining_XOPEN_SOURCEto >= 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 500should be sufficient.In summary: setting _XOPEN_SOURCE to 700 at the top of
lib/ipmi_main.cis incorrect, as it causes the getpass() prototype to not be used. Changing it to 500 causes the segfault to go away. The_BSD_SOURCEdefine is not needed. Simple patch attached.