diff -Nrup gdb.orig/main.c gdb/main.c --- gdb.orig/main.c 2005-10-07 19:41:19.000000000 -0400 +++ gdb/main.c 2005-10-07 20:11:10.000000000 -0400 @@ -40,6 +40,7 @@ #include "interps.h" #include "main.h" +#include "paxflags.c" /* If nonzero, display time usage both at startup and for each command. */ @@ -635,6 +636,9 @@ extern int gdbtk_test (char *); catch_command_errors (directory_command, dirarg[i], 0, RETURN_MASK_ALL); xfree (dirarg); + if (execarg != NULL) + check_pax_flags(execarg); + if (execarg != NULL && symarg != NULL && strcmp (execarg, symarg) == 0) diff -Nrup gdb.orig/paxflags.c gdb/paxflags.c --- gdb.orig/paxflags.c 1969-12-31 19:00:00.000000000 -0500 +++ gdb/paxflags.c 2005-10-07 20:17:20.000000000 -0400 @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +static char *get_proc_status(pid_t pid, const char *name) +{ + FILE *fp; + size_t len; + static char str[_POSIX_PATH_MAX]; + + snprintf(str, sizeof(str), "/proc/%u/status", pid); + if ((fp = fopen(str, "r")) == NULL) + return NULL; + + len = strlen(name); + while (fgets(str, sizeof(str), fp)) { + if (strncasecmp(str, name, len) == 0) { + if (str[len] == ':') { + fclose(fp); + str[strlen(str) - 1] = 0; + return (str + len + 2); + } + } + } + fclose(fp); + return NULL; +} + +void check_pax_flags(char *file) +{ + char *buf; + size_t len; + FILE *fp; + + if ((get_proc_status(getpid(), "PaX")) == NULL) + return; + + if (access(file, R_OK) != 0) + return; + + asprintf(&buf, + "type -p scanelf >/dev/null && scanelf -BF%%x %s|awk '{print $1}'|sed s@-@@g", + file); + len = strlen(buf); + fp = popen(buf, "r"); + fgets(buf, len - 1, fp); + pclose(fp); + + if (buf[0] == 0) { + free(buf); + return; + } + + len = strlen(buf); + if (len && len < 10) { + buf[len - 1] = 0; + if (((strchr(buf, 'p')) == NULL) || ((strchr(buf, 's')) == NULL) + || ((strchr(buf, 'm')) == NULL)) + printf("\n(PaX appears to be enabled) Try paxctl -srpm %s\n", file); + } + free(buf); +}