Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] windows-nat: Remove SO_NAME_MAX_PATH_SIZE limit
Date: Fri, 22 Mar 2024 19:04:23 +0000	[thread overview]
Message-ID: <20240322190424.1231540-4-pedro@palves.net> (raw)
In-Reply-To: <20240322190424.1231540-1-pedro@palves.net>

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.

Change-Id: I79e9862d5a7646eebfef7ab5b05b96318a7ca0c5
---
 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;
 	}
     }
-- 
2.43.2


  parent reply	other threads:[~2024-03-22 19:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 19:04 [PATCH 0/4] Down with SO_NAME_MAX_PATH_SIZE and windows_make_so spring cleaning Pedro Alves
2024-03-22 19:04 ` [PATCH 1/4] Remove SO_NAME_MAX_PATH_SIZE limit from core solib code Pedro Alves
2024-03-22 19:04 ` [PATCH 2/4] Simplify windows-nat.c:windows_make_so #ifdefery Pedro Alves
2024-03-22 19:04 ` Pedro Alves [this message]
2024-03-22 19:04 ` [PATCH 4/4] windows-nat: Use gdb_realpath Pedro Alves
2024-03-22 19:37 ` [PATCH 0/4] Down with SO_NAME_MAX_PATH_SIZE and windows_make_so spring cleaning John Baldwin
2024-03-22 19:49   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240322190424.1231540-4-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox