[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] gawk branch, stable/pma-update, updated. gawk-4.1.0-5605-g125b63ec
From: |
Arnold Robbins |
Subject: |
[SCM] gawk branch, stable/pma-update, updated. gawk-4.1.0-5605-g125b63ec |
Date: |
Sat, 1 Feb 2025 12:32:36 -0500 (EST) |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, stable/pma-update has been updated
via 125b63ecb47c871cb73f17e01b0f1cedc07e04a9 (commit)
from c968c7ac3c2a56e73ea0455c73449af930945bcd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=125b63ecb47c871cb73f17e01b0f1cedc07e04a9
commit 125b63ecb47c871cb73f17e01b0f1cedc07e04a9
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Sat Feb 1 19:32:05 2025 +0200
Add code for macos so don't need -no-pie.
diff --git a/ChangeLog b/ChangeLog
index 0bc5c82d..432faa98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-02-01 Arnold D. Robbins <arnold@skeeve.com>
+
+ * configure.ac: Add checks for spawn.h and _NSGetExecutablePath
+ function.
+ * awk.h (os_disable_aslr): Add function declaration.
+ * main.c (enable_pma): Move OS specific code out of this function
+ and in posix/gawkmisc.c. Instead, call os_disable_aslr().
+
2025-01-30 Arnold D. Robbins <arnold@skeeve.com>
* main.c (enable_pma): Remove unused argc parameter and adjust
diff --git a/awk.h b/awk.h
index 9bfbd1ee..bc576ac5 100644
--- a/awk.h
+++ b/awk.h
@@ -1630,6 +1630,7 @@ extern int os_is_setuid(void);
extern int os_setbinmode(int fd, int mode);
extern void os_restore_mode(int fd);
extern void os_maybe_set_errno(void);
+extern void os_disable_aslr(const char *persist_file, char **argv);
extern size_t optimal_bufsize(int fd, struct stat *sbuf);
extern int ispath(const char *file);
extern int isdirpunct(int c);
diff --git a/configh.in b/configh.in
index 306f7b9d..885c4b91 100644
--- a/configh.in
+++ b/configh.in
@@ -204,6 +204,9 @@
/* we have sockets on this system */
#undef HAVE_SOCKETS
+/* Define to 1 if you have the <spawn.h> header file. */
+#undef HAVE_SPAWN_H
+
/* Define to 1 if you have the <stdbool.h> header file. */
#undef HAVE_STDBOOL_H
@@ -362,6 +365,9 @@
/* systems should define this type here */
#undef HAVE_WINT_T
+/* Define to 1 if you have the `_NSGetExecutablePath' function. */
+#undef HAVE__NSGETEXECUTABLEPATH
+
/* Define to 1 if you have the `__etoa_l' function. */
#undef HAVE___ETOA_L
diff --git a/configure b/configure
index 29cb8b8d..2c2e2b03 100755
--- a/configure
+++ b/configure
@@ -10306,6 +10306,12 @@ if test "x$ac_cv_header_string_h" = xyes
then :
printf "%s\n" "#define HAVE_STRING_H 1" >>confdefs.h
+fi
+ac_fn_c_check_header_compile "$LINENO" "spawn.h" "ac_cv_header_spawn_h"
"$ac_includes_default"
+if test "x$ac_cv_header_spawn_h" = xyes
+then :
+ printf "%s\n" "#define HAVE_SPAWN_H 1" >>confdefs.h
+
fi
ac_fn_c_check_header_compile "$LINENO" "sys/ioctl.h"
"ac_cv_header_sys_ioctl_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_ioctl_h" = xyes
@@ -11720,6 +11726,12 @@ if test "x$ac_cv_func_memset" = xyes
then :
printf "%s\n" "#define HAVE_MEMSET 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "_NSGetExecutablePath"
"ac_cv_func__NSGetExecutablePath"
+if test "x$ac_cv_func__NSGetExecutablePath" = xyes
+then :
+ printf "%s\n" "#define HAVE__NSGETEXECUTABLEPATH 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "mkstemp" "ac_cv_func_mkstemp"
if test "x$ac_cv_func_mkstemp" = xyes
@@ -12032,17 +12044,7 @@ fi
true # On Linux we no longer need -no-pie
;;
*darwin*)
- # 27 November 2022: PMA only works on Intel.
- case $host in
- x86_64-*)
- LDFLAGS="${LDFLAGS} -Xlinker -no_pie"
- export LDFLAGS
- ;;
- *)
- # disable on all other macOS systems
- use_persistent_malloc=no
- ;;
- esac
+ true # On macos we no longer need -no-pie
;;
*cygwin* | *CYGWIN* | *solaris2.11* | freebsd13.* | openbsd7.* )
true # nothing to do, exes on these systems are not
PIE
diff --git a/configure.ac b/configure.ac
index 6570aa5b..015e18ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -187,6 +187,7 @@ gt_LC_MESSAGES
dnl checks for header files
AC_CHECK_HEADERS(arpa/inet.h fcntl.h locale.h libintl.h mcheck.h \
netdb.h netinet/in.h stddef.h string.h \
+ spawn.h \
sys/ioctl.h sys/param.h sys/personality.h sys/select.h sys/socket.h
sys/time.h \
unistd.h termios.h stropts.h wchar.h wctype.h)
@@ -317,6 +318,7 @@ AC_CHECK_FUNCS(__etoa_l atexit btowc fmod fwrite_unlocked
gai_strerror \
gettimeofday clock_gettime lstat \
getdtablesize \
mbrlen memcmp memcpy memmove memset \
+ _NSGetExecutablePath \
mkstemp mtrace personality posix_openpt setenv setlocale setsid
sigprocmask \
snprintf strcasecmp strchr strcoll strerror strftime strncasecmp \
strsignal strtod strtoul system timegm tmpfile towlower towupper \
diff --git a/m4/ChangeLog b/m4/ChangeLog
index bab71faf..8498a9ac 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,8 @@
+2025-02-01 Arnold D. Robbins <arnold@skeeve.com>
+
+ * pma.m4: On macos, no longer need to do anything special,
+ but we do have to have a case for it so that PMA is enabled.
+
2025-01-29 Arnold D. Robbins <arnold@skeeve.com>
* pma.m4: On Linux, no longer need to do anything special,
diff --git a/m4/pma.m4 b/m4/pma.m4
index 6bc67a0d..f270f4f3 100644
--- a/m4/pma.m4
+++ b/m4/pma.m4
@@ -22,17 +22,7 @@ then
true # On Linux we no longer need -no-pie
;;
*darwin*)
- # 27 November 2022: PMA only works on Intel.
- case $host in
- x86_64-*)
- LDFLAGS="${LDFLAGS} -Xlinker -no_pie"
- export LDFLAGS
- ;;
- *)
- # disable on all other macOS systems
- use_persistent_malloc=no
- ;;
- esac
+ true # On macos we no longer need -no-pie
;;
*cygwin* | *CYGWIN* | *solaris2.11* | freebsd13.* | openbsd7.* )
true # nothing to do, exes on these systems are not
PIE
diff --git a/main.c b/main.c
index ebccf43f..191e2b6a 100644
--- a/main.c
+++ b/main.c
@@ -34,10 +34,6 @@
#include <mcheck.h>
#endif
-#ifdef HAVE_SYS_PERSONALITY_H
-#include <sys/personality.h>
-#endif
-
#define DEFAULT_PROFILE "awkprof.out" /* where to put profile
*/
#define DEFAULT_VARFILE "awkvars.out" /* where to put vars */
#define DEFAULT_PREC 53
@@ -1916,6 +1912,8 @@ check_pma_security(const char *pma_file)
#endif /* USE_PERSISTENT_MALLOC */
}
+//#include <libproc.h>
+#include <spawn.h>
/* enable_pma --- do the PMA flow, handle ASLR on Linux */
@@ -1930,35 +1928,7 @@ enable_pma(char **argv)
return false;
}
#else
-#ifdef HAVE_PERSONALITY
- // This code is Linux specific, both the reliance on /proc/self/exe
- // and the personality system call.
- if (persist_file != NULL) {
- const char *cp = getenv("GAWK_PMA_REINCARNATION");
-
- if (cp == NULL) {
- char fullpath[BUFSIZ];
- int n;
-
- if ((n = readlink("/proc/self/exe", fullpath,
sizeof(fullpath)-1)) < 0) {
- fprintf(stderr, _("warning: /proc/self/exe:
readlink: %s\n"),
- strerror(errno));
- goto init;
- }
- fullpath[n] = '\0';
- putenv("GAWK_PMA_REINCARNATION=true");
- if (personality(PER_LINUX | ADDR_NO_RANDOMIZE) < 0) {
- fprintf(stderr, _("warning: personality: %s\n"),
- strerror(errno));
- fflush(stderr);
- // do the exec anyway...
- }
- execv(fullpath, argv);
- } else
- (void) unsetenv("GAWK_PMA_REINCARNATION");
- }
-init:
-#endif /* HAVE_PERSONALITY */
+ os_disable_aslr(persist_file, argv);
check_pma_security(persist_file);
int pma_result = pma_init(1, persist_file);
diff --git a/posix/ChangeLog b/posix/ChangeLog
index 28f74e96..09247343 100644
--- a/posix/ChangeLog
+++ b/posix/ChangeLog
@@ -1,3 +1,7 @@
+2025-02-01 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawkmisc.c (os_disable_aslr): New function for *nix.
+
2024-09-17 Arnold D. Robbins <arnold@skeeve.com>
* 5.3.1: Release tar made.
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c
index 0b30d746..a089d18c 100644
--- a/posix/gawkmisc.c
+++ b/posix/gawkmisc.c
@@ -1,6 +1,7 @@
/* gawkmisc.c --- miscellaneous gawk routines that are OS specific.
- Copyright (C) 1986, 1988, 1989, 1991 - 1998, 2001 - 2004, 2011, 2021, 2022,
2023,
+ Copyright (C) 1986, 1988, 1989, 1991 - 1998, 2001 - 2004, 2011,
+ 2021, 2022, 2023, 2025,
the Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -26,6 +27,14 @@
#include <io.h> /* for declaration of setmode(). */
#endif
+#ifdef HAVE_SYS_PERSONALITY_H // for linux
+#include <sys/personality.h>
+#endif
+
+#ifdef HAVE_SPAWN_H
+#include <spawn.h> // for macos
+#endif
+
const char quote = '\'';
const char *defpath = DEFPATH;
const char *deflibpath = DEFLIBPATH;
@@ -297,6 +306,81 @@ os_maybe_set_errno(void)
{
}
+/* os_disable_aslr --- disable Address Space Layout Randomization */
+
+void
+os_disable_aslr(const char *persist_file, char **argv)
+{
+#ifdef HAVE_PERSONALITY
+ // This code is Linux specific, both the reliance on /proc/self/exe
+ // and the personality system call.
+ if (persist_file != NULL) {
+ const char *cp = getenv("GAWK_PMA_REINCARNATION");
+
+ if (cp == NULL) {
+ char fullpath[BUFSIZ];
+ int n;
+
+ if ((n = readlink("/proc/self/exe", fullpath,
sizeof(fullpath)-1)) < 0) {
+ fprintf(stderr, _("warning: /proc/self/exe:
readlink: %s\n"),
+ strerror(errno));
+ return;
+ }
+ fullpath[n] = '\0';
+ putenv("GAWK_PMA_REINCARNATION=true");
+ if (personality(PER_LINUX | ADDR_NO_RANDOMIZE) < 0) {
+ fprintf(stderr, _("warning: personality: %s\n"),
+ strerror(errno));
+ fflush(stderr);
+ // do the exec anyway...
+ }
+ execv(fullpath, argv);
+ } else
+ (void) unsetenv("GAWK_PMA_REINCARNATION");
+ }
+#endif
+#ifdef HAVE__NSGETEXECUTABLEPATH
+ // This code is for macos
+ if (persist_file != NULL) {
+ const char *cp = getenv("GAWK_PMA_REINCARNATION");
+
+ if (cp == NULL) {
+ char fullpath[BUFSIZ];
+ int n;
+ posix_spawnattr_t p_attr;
+ int status;
+ pid_t pid;
+ extern char **environ;
+ size_t size = BUFSIZ;
+
+ memset(fullpath, 0, BUFSIZ);
+ n = _NSGetExecutablePath(fullpath, &size);
+
+ putenv("GAWK_PMA_REINCARNATION=true");
+
+ posix_spawnattr_init(&p_attr);
+ posix_spawnattr_setflags(&p_attr, 0x100);
+ status = posix_spawnp(&pid, fullpath, NULL, &p_attr,
argv, environ);
+ if (status == 0) {
+ if (waitpid(pid, &status, WUNTRACED) != -1) {
+ if (WIFEXITED(status))
+ exit WEXITSTATUS(status);
// use original exit code
+ } else {
+ fprintf(stderr, _("waitpid: got exit
status %#o\n"), status);
+ exit(EXIT_FATAL);
+ }
+ } else {
+ fprintf(stderr, _("fatal: posix_spawn: %s\n"),
sterror(errno));
+ exit(EXIT_FATAL);
+ }
+ } else
+ (void) unsetenv("GAWK_PMA_REINCARNATION");
+ }
+#endif
+}
+
+// This for Linux and MacOS. It's not needed on other *nix systems.
+
// For MSYS, restore behavior of working in text mode.
#ifdef __MSYS__
void
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 8 ++++++
awk.h | 1 +
configh.in | 6 ++++
configure | 24 ++++++++--------
configure.ac | 2 ++
m4/ChangeLog | 5 ++++
m4/pma.m4 | 12 +-------
main.c | 36 ++----------------------
posix/ChangeLog | 4 +++
posix/gawkmisc.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
10 files changed, 128 insertions(+), 56 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] gawk branch, stable/pma-update, updated. gawk-4.1.0-5605-g125b63ec,
Arnold Robbins <=