Browse Source
I noticed that gdb could leak file descriptors coming from mkstemp. This patch fixes the problem by importing the gnulib mkostemp instead, and then changing gdb to pass O_CLOEXEC. A small gnulib patch was needed. This has already been accepted upstream. gdb/ChangeLog 2018-10-27 Tom Tromey <tom@tromey.com> * unittests/scoped_mmap-selftests.c (test_normal): Use gdb_mkostemp_cloexec. * unittests/scoped_fd-selftests.c (test_destroy, test_release): Use gdb_mkostemp_cloexec. * gnulib/aclocal-m4-deps.mk, gnulib/aclocal.m4, gnulib/config.in, gnulib/configure, gnulib/import/Makefile.am, gnulib/import/Makefile.in, gnulib/import/m4/gnulib-cache.m4, gnulib/import/m4/gnulib-comp.m4: Update. * gnulib/import/m4/mkostemp.m4: New file. * gnulib/import/m4/mkstemp.m4: Remove. * gnulib/import/mkostemp.c: New file. * gnulib/import/mkstemp.m4: Remove. * gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Remove mkstemp, add mkostemp. Apply new patch. * gnulib/import/stdlib.in.h: Apply patch. * gnulib/patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch: New file. * dwarf-index-write.c (write_psymtabs_to_index): Use gdb_mkostemp_cloexec. * common/filestuff.h (gdb_mkostemp_cloexec): New function.users/ahayward/variable_sve2
19 changed files with 162 additions and 207 deletions
@ -0,0 +1,23 @@ |
|||
# mkostemp.m4 serial 2 |
|||
dnl Copyright (C) 2009-2016 Free Software Foundation, Inc. |
|||
dnl This file is free software; the Free Software Foundation |
|||
dnl gives unlimited permission to copy and/or distribute it, |
|||
dnl with or without modifications, as long as this notice is preserved. |
|||
|
|||
AC_DEFUN([gl_FUNC_MKOSTEMP], |
|||
[ |
|||
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
|||
|
|||
dnl Persuade glibc <stdlib.h> to declare mkostemp(). |
|||
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
|||
|
|||
AC_CHECK_FUNCS_ONCE([mkostemp]) |
|||
if test $ac_cv_func_mkostemp != yes; then |
|||
HAVE_MKOSTEMP=0 |
|||
fi |
|||
]) |
|||
|
|||
# Prerequisites of lib/mkostemp.c. |
|||
AC_DEFUN([gl_PREREQ_MKOSTEMP], |
|||
[ |
|||
]) |
|||
@ -1,82 +0,0 @@ |
|||
#serial 23 |
|||
|
|||
# Copyright (C) 2001, 2003-2007, 2009-2016 Free Software Foundation, Inc. |
|||
# This file is free software; the Free Software Foundation |
|||
# gives unlimited permission to copy and/or distribute it, |
|||
# with or without modifications, as long as this notice is preserved. |
|||
|
|||
# On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a |
|||
# silly limit that it can create no more than 26 files from a given template. |
|||
# Other systems lack mkstemp altogether. |
|||
# On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create |
|||
# only 32 files per process. |
|||
# On some hosts, mkstemp creates files with mode 0666, which is a security |
|||
# problem and a violation of POSIX 2008. |
|||
# On systems like the above, arrange to use the replacement function. |
|||
AC_DEFUN([gl_FUNC_MKSTEMP], |
|||
[ |
|||
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
|||
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
|||
|
|||
AC_CHECK_FUNCS_ONCE([mkstemp]) |
|||
if test $ac_cv_func_mkstemp = yes; then |
|||
AC_CACHE_CHECK([for working mkstemp], |
|||
[gl_cv_func_working_mkstemp], |
|||
[ |
|||
mkdir conftest.mkstemp |
|||
AC_RUN_IFELSE( |
|||
[AC_LANG_PROGRAM( |
|||
[AC_INCLUDES_DEFAULT], |
|||
[[int result = 0; |
|||
int i; |
|||
off_t large = (off_t) 4294967295u; |
|||
if (large < 0) |
|||
large = 2147483647; |
|||
umask (0); |
|||
for (i = 0; i < 70; i++) |
|||
{ |
|||
char templ[] = "conftest.mkstemp/coXXXXXX"; |
|||
int (*mkstemp_function) (char *) = mkstemp; |
|||
int fd = mkstemp_function (templ); |
|||
if (fd < 0) |
|||
result |= 1; |
|||
else |
|||
{ |
|||
struct stat st; |
|||
if (lseek (fd, large, SEEK_SET) != large) |
|||
result |= 2; |
|||
if (fstat (fd, &st) < 0) |
|||
result |= 4; |
|||
else if (st.st_mode & 0077) |
|||
result |= 8; |
|||
if (close (fd)) |
|||
result |= 16; |
|||
} |
|||
} |
|||
return result;]])], |
|||
[gl_cv_func_working_mkstemp=yes], |
|||
[gl_cv_func_working_mkstemp=no], |
|||
[case "$host_os" in |
|||
# Guess yes on glibc systems. |
|||
*-gnu*) gl_cv_func_working_mkstemp="guessing yes" ;; |
|||
# If we don't know, assume the worst. |
|||
*) gl_cv_func_working_mkstemp="guessing no" ;; |
|||
esac |
|||
]) |
|||
rm -rf conftest.mkstemp |
|||
]) |
|||
case "$gl_cv_func_working_mkstemp" in |
|||
*yes) ;; |
|||
*) |
|||
REPLACE_MKSTEMP=1 |
|||
;; |
|||
esac |
|||
else |
|||
HAVE_MKSTEMP=0 |
|||
fi |
|||
]) |
|||
|
|||
# Prerequisites of lib/mkstemp.c. |
|||
AC_DEFUN([gl_PREREQ_MKSTEMP], |
|||
[ |
|||
]) |
|||
@ -0,0 +1,38 @@ |
|||
From 6954995dd32ea98a1973df31f411f3996bb47dfb Mon Sep 17 00:00:00 2001 |
|||
From: Tom Tromey <tom@tromey.com> |
|||
Date: Mon, 1 Oct 2018 14:57:45 -0600 |
|||
Subject: [PATCH] mkostemp, mkostemps: Fix compilation error in C++ mode on Mac |
|||
OS X. |
|||
|
|||
Attempting to use the mkostemp module in gdb caused a build failure |
|||
when using the C++ namespace feature, because mkostemp was not |
|||
declared. On OS X, mkostemp is declared in unistd.h, so this patch |
|||
extends the existing special case in stdlib.in.h to cover mkostemp and |
|||
mkostemps. |
|||
|
|||
* lib/stdlib.in.h: Include <unistd.h> for mkostemp and mkostemps |
|||
on OS X. |
|||
---
|
|||
ChangeLog | 6 ++++++ |
|||
lib/stdlib.in.h | 3 ++- |
|||
2 files changed, 8 insertions(+), 1 deletion(-) |
|||
|
|||
diff --git a/gdb/gnulib/import/stdlib.in.h b/gdb/gnulib/import/stdlib.in.h
|
|||
index db3253bd97..8f803a2ea3 100644
|
|||
--- a/gdb/gnulib/import/stdlib.in.h
|
|||
+++ b/gdb/gnulib/import/stdlib.in.h
|
|||
@@ -87,9 +87,10 @@ struct random_data
|
|||
# endif |
|||
#endif |
|||
|
|||
-#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
|
|||
+#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_MKOSTEMP@ || @GNULIB_MKOSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
|
|||
/* On Mac OS X 10.3, only <unistd.h> declares mkstemp. */ |
|||
/* On Mac OS X 10.5, only <unistd.h> declares mkstemps. */ |
|||
+/* On Mac OS X 10.13, only <unistd.h> declares mkostemp and mkostemps. */
|
|||
/* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */ |
|||
/* But avoid namespace pollution on glibc systems and native Windows. */ |
|||
# include <unistd.h> |
|||
--
|
|||
2.19.0 |
|||
|
|||
Loading…
Reference in new issue