Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Better handling for realpath() failures in windows_make_so() on Cygwin
@ 2016-01-20 15:54 Jon Turney
  2016-01-20 16:19 ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Jon Turney @ 2016-01-20 15:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jon Turney

Fix a memory leak which would occur in the case when the result of realpath() is
greater than or equal to SO_NAME_MAX_PATH_SIZE.

Distinguish between realpath() failing (returning NULL), and returning a path
greather than or equal to SO_NAME_MAX_PATH_SIZE.

Warn rather than stopping with an error in both those cases.

Original patch from Tim Chick.  Memory leak fix by Corinna Vinschen.

See also https://cygwin.com/ml/cygwin/2015-11/msg00353.html

gdb/ChangeLog:

2016-01-20  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (windows_make_so): Fix memory leak when realpath
	returns a path >= SO_NAME_MAX_PATH_SIZE.  Distinguish that case
	from realpath failing.  Warn rather than stopping with an error in
	both cases.
---
 gdb/ChangeLog     |  7 +++++++
 gdb/windows-nat.c | 15 ++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 71d6670..703b407 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -642,13 +642,22 @@ windows_make_so (const char *name, LPVOID load_addr)
   else
     {
       char *rname = realpath (name, NULL);
-      if (rname && strlen (rname) < SO_NAME_MAX_PATH_SIZE)
+      if (rname)
 	{
-	  strcpy (so->so_name, rname);
+	  if (strlen (rname) < SO_NAME_MAX_PATH_SIZE)
+	    strcpy (so->so_name, rname);
+	  else
+	    {
+	      warning (_("dll path \"%s\" too long"), rname);
+	      strcpy (so->so_name, so->so_original_name);
+	    }
 	  free (rname);
 	}
       else
-	error (_("dll path too long"));
+	{
+	  warning (_("dll path for \"%s\" can not be evaluated"), name);
+	  strcpy (so->so_name, so->so_original_name);
+	}
     }
   /* Record cygwin1.dll .text start/end.  */
   p = strchr (so->so_name, '\0') - (sizeof ("/cygwin1.dll") - 1);
-- 
2.7.0


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] Better handling for realpath() failures in windows_make_so() on Cygwin
@ 2024-03-21  6:53 Orgad Shaneh
  2024-03-21  7:22 ` Orgad Shaneh
  2024-03-21 14:45 ` Jon Turney
  0 siblings, 2 replies; 11+ messages in thread
From: Orgad Shaneh @ 2024-03-21  6:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jon Turney

From: Jon Turney <jon.turney@dronecode.org.uk>

Fix a memory leak which would occur in the case when the result of realpath() is
greater than or equal to SO_NAME_MAX_PATH_SIZE.

Distinguish between realpath() failing (returning NULL), and returning a path
longer than SO_NAME_MAX_PATH_SIZE

Warn rather than stopping with an error in those cases.

Original patch from Tim Chick.  Memory leak fix by Corinna Vinschen.
---
 gdb/windows-nat.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index a90388922e2..7dc2bb2a115 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -892,6 +892,10 @@ windows_make_so (const char *name, LPVOID load_addr)
 	{
 	  warning (_("dll path for \"%s\" too long or inaccessible"), name);
 	  so->name = so->original_name;
+	  if (rname)
+	    {
+	      free (rname);
+	    }
 	}
     }
   /* Record cygwin1.dll .text start/end.  */
-- 
2.44.0.windows.1.1.g2942425c99


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-03-22 19:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 15:54 [PATCH] Better handling for realpath() failures in windows_make_so() on Cygwin Jon Turney
2016-01-20 16:19 ` Pedro Alves
2016-03-09 17:49   ` Jon Turney
2016-03-09 18:09     ` Pedro Alves
2024-03-21  6:53 Orgad Shaneh
2024-03-21  7:22 ` Orgad Shaneh
2024-03-21 15:04   ` Tom Tromey
2024-03-21 14:45 ` Jon Turney
2024-03-21 16:13   ` Pedro Alves
2024-03-21 16:31     ` Orgad Shaneh
2024-03-22 19:07       ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox