This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

access on non-existing file and catchsegv



Matthias reports in PR libc/2345 that catchsegv only calls addrline if
the file already exists.

Looking into the problem in more detail, I found that we have the
following code in sysdeps/generic/segfault.c:

  /* Preserve the output file name if there is any given.  */
  name = getenv ("SEGFAULT_OUTPUT_NAME");
  if (name != NULL && name[0] != '\0' && access (name, R_OK | W_OK) == 0)
    fname = __strdup (name);

Since the file does not exist, access sets ENOENT and returns with -1
- and we do not create the file in that case.  Therefore the test is
broken.  The question is now how to fix this.

Matthias found as a workaround to just touch the file in catchsegv but
this does not work in general.

I propose to check also whether the file exists.

I'm appending a patch.  What do you think?

Andreas

2001-07-01  Andreas Jaeger  <aj@suse.de>

	* sysdeps/generic/segfault.c (install_handler): Handle case that
	the output file does not exists.
	Closes PR libc/2345.

============================================================
Index: sysdeps/generic/segfault.c
--- sysdeps/generic/segfault.c	2001/01/12 17:34:37	1.14
+++ sysdeps/generic/segfault.c	2001/07/01 12:14:04
@@ -237,6 +237,11 @@
 
   /* Preserve the output file name if there is any given.  */
   name = getenv ("SEGFAULT_OUTPUT_NAME");
-  if (name != NULL && name[0] != '\0' && access (name, R_OK | W_OK) == 0)
-    fname = __strdup (name);
+  if (name != NULL && name[0] != '\0')
+    {
+      int ret = access (name, R_OK | W_OK);
+      
+      if (ret == 0 || (ret == -1 && errno == ENOENT))
+	fname = __strdup (name);
+    }
 }

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]