The original bug for this is #436 
(https://sourceforge.net/p/ipmitool/bugs/436/), which was closed as duplicate 
and fixed on GNU platforms by compiling with -std=gnu99.

However, it is not fixed on macOS, as I noted at: 
https://sourceforge.net/p/ipmitool/bugs/433/#89ea


I’ll just copy that message here (with minor editing):

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 on macOS, unlike e.g FreeBSD & OpenBSD which use
something like
#if (defined _BSD_SOURCE) || (_XOPEN_SOURCE <= 500)

Here is the 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 #433).

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();
note that defining _XOPEN_SOURCE to >= 600 will *not* include getpass().
If _BSD_SOURCE is 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 to #433.


Besides macOS (10.12.5), I have also tested the patch on Linux (SLES 12 SP2), 
FreeBSD (11.0), and OpenBSD (6.1), and it also works on all of those platforms.



Regards,

Andrew

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ipmitool-devel mailing list
Ipmitool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel

Reply via email to