I am getting a core dump with a program compiled with gcc-4.1.2 (64bit). The program crashed inside the function call pam_authenticate. The program uses the pam library and is compiled by the following command: gcc-4.1.2/bin/gcc -mlp64 pam_test.c -lpam -o pt -bash-3.00$ ldd pt libpam.so.1 => /lib/hpux64/libpam.so.1 libunwind.so.1 => /lib/hpux64/libunwind.so.1 libc.so.1 => /lib/hpux64/libc.so.1 libuca.so.1 => /usr/lib/hpux64/libuca.so.1 libdl.so.1 => /usr/lib/hpux64/libdl.so.1 If compiled with 32bit, the program works fine. gcc-4.1.2/bin/gcc pam_test.c -lpam -o pt -bash-3.00$ ldd pt libpam.so.1 => /usr/lib/hpux32/libpam.so.1 libunwind.so.1 => /usr/lib/hpux32/libunwind.so.1 libc.so.1 => /usr/lib/hpux32/libc.so.1 libuca.so.1 => /usr/lib/hpux32/libuca.so.1 libdl.so.1 => /usr/lib/hpux32/libdl.so.1 When compiled using gcc-3.4, it works fine on both 64 and 32 bit. -bash-3.00$ gcc-3.4/bin/gcc -mlp64 pam_test.c -lpam -o pt -bash-3.00$ ldd pt libpam.so.1 => /lib/hpux64/libpam.so.1 libc.so.1 => /lib/hpux64/libc.so.1 libdl.so.1 => /usr/lib/hpux64/libdl.so.1 We built gcc-4.1.2 from the source with the following configuration and with binutil-2.17. Configured with: /home/gcc-4.1.2/configure --prefix=/usr/local/gcc-4.1.2 --enable-languages=c,c++ --enable-threads=posix --with-gnu-as --without-gnu-ld --with-as=/usr/local/gcc-4.1.2/bin/as Is this likely a gcc bug? --------------------------------------------------------- #include <pwd.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <security/pam_appl.h> const char *PAM_username = "guest"; const char *PAM_password = "guest"; static int PAM_conv (int num_msg, struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) { struct pam_response *repl = NULL; int count = 0, replies = 0; int size = sizeof(struct pam_response); printf("In PAM_conv:num_msg:%i\n",num_msg); for(count = 0; count < num_msg; count++) { switch(msg[0]->msg_style) { case PAM_PROMPT_ECHO_ON: printf("PAM_conv:PAM_PROMPT_ECHO_ON\n"); if (!(repl = (struct pam_response*)realloc(repl, size))) { return PAM_CONV_ERR; } size += sizeof(struct pam_response); repl[replies].resp_retcode = PAM_SUCCESS; repl[replies].resp = strdup(PAM_username); replies++; break; case PAM_PROMPT_ECHO_OFF: printf("PAM_conv:PAM_PROMPT_ECHO_OFF\n"); if (!(repl = (struct pam_response*)realloc(repl, size))) { return PAM_CONV_ERR; } size += sizeof(struct pam_response); repl[replies].resp_retcode = PAM_SUCCESS; repl[replies].resp = strdup(PAM_password); break; default: break; } } if (repl) { *resp = repl; } return PAM_SUCCESS; } int main() { static struct pam_conv conv = { &PAM_conv, NULL }; pam_handle_t *pamh = NULL; int retval; retval = pam_start("su", PAM_username, &conv, &pamh); if (retval != PAM_SUCCESS) printf("pam_start() failed.\n"); printf("authenticate--- do not crash\n"); retval = pam_authenticate(pamh, 0); printf("authenticate-- \n"); if (retval != PAM_SUCCESS) { printf("PAM authentication failed.\n"); } else { printf("PAM authentication OK.\n"); } pam_end(pamh, PAM_SUCCESS); return 1; }
Compile with -Wl,-Z and it succeeds: gcc-4.1.2/bin/gcc -mlp64 pam_test.c -lpam -o pt -Wl,-Z It appears libpam on hpux requires -Z. It was removed here: http://gcc.gnu.org/ml/gcc-patches/2005-03/msg00542.html
I am resolving this as invalid since it is not a GCC bug (unless you consider not using -Z to be a bug). There is a patch for libpam which should fix the null pointer reference available from HP. It is HP patch PHCO_37076.