public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] windows-nat: Remove SO_NAME_MAX_PATH_SIZE limit
@ 2024-03-22 19:48 Pedro Alves
  0 siblings, 0 replies; only message in thread
From: Pedro Alves @ 2024-03-22 19:48 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=30512efab1478ece80cf98d00eb70681afaf7412

commit 30512efab1478ece80cf98d00eb70681afaf7412
Author: Pedro Alves <pedro@palves.net>
Date:   Fri Mar 22 19:46:59 2024 +0000

    windows-nat: Remove SO_NAME_MAX_PATH_SIZE limit
    
    There is no need to limit shared library path sizes to
    SO_NAME_MAX_PATH_SIZE nowadays.  windows_solib::name and
    windows_solib::original_name are std::strings nowadays, and so are
    solib::so_name and solib::so_original_name in the core solib code.
    
    This commit reworks the code to remove that limit.  This also fixes a
    leak where we were not releasing 'rname' in the realpath branch if the
    'rname' string was larger than SO_NAME_MAX_PATH_SIZE.
    
    Note: I tested the cygwin_conv_path with a manual hack to force that
    path, and then stepping through the code.  You only get to that path
    if Windows doesn't report an absolute path for ntdll.dll, and on my
    machine (running Windows 10), it always does.
    
    Approved-By: John Baldwin <jhb@FreeBSD.org>
    Change-Id: I79e9862d5a7646eebfef7ab5b05b96318a7ca0c5

Diff:
---
 gdb/windows-nat.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index a01011248c1..278bfb0e1f1 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -874,22 +874,32 @@ windows_make_so (const char *name, LPVOID load_addr)
     }
   if (buf[0])
     {
-      char cname[SO_NAME_MAX_PATH_SIZE];
-      cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, cname,
-			SO_NAME_MAX_PATH_SIZE);
-      so->name = cname;
+      bool ok = false;
+
+      /* Check how big the output buffer has to be.  */
+      ssize_t size = cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, nullptr, 0);
+      if (size > 0)
+	{
+	  /* SIZE includes the null terminator.  */
+	  so->name.resize (size - 1);
+	  if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, so->name.data (),
+				size) == 0)
+	    ok = true;
+	}
+      if (!ok)
+	so->name = so->original_name;
     }
   else
     {
       char *rname = realpath (name, NULL);
-      if (rname && strlen (rname) < SO_NAME_MAX_PATH_SIZE)
+      if (rname != nullptr)
 	{
 	  so->name = rname;
 	  free (rname);
 	}
       else
 	{
-	  warning (_("dll path for \"%s\" too long or inaccessible"), name);
+	  warning (_("dll path for \"%s\" inaccessible"), name);
 	  so->name = so->original_name;
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-22 19:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 19:48 [binutils-gdb] windows-nat: Remove SO_NAME_MAX_PATH_SIZE limit Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).