Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 9/9] [GDBserver] hostio.c: Fallback to packet buffer size if PATH_MAX is not available.
Date: Thu, 27 Jun 2013 18:59:00 -0000	[thread overview]
Message-ID: <20130627185304.6625.18112.stgit@brno.lan> (raw)
In-Reply-To: <20130627185200.6625.10526.stgit@brno.lan>

PATH_MAX is not defined on systems which have no limit on filename
length, such as GNU/Hurd.  As designed, the hostio RSP packets carry
the paths as parameters in the request/reply packets, which themselves
have an upper size limit, so lifting the filename limit completely
would require a redesign with new hostio packets.  While that doesn't
happen, we can at least support filename lengths as long as the packet
buffer can fit.

gdb/
2013-06-27  Pedro Alves  <palves@redhat.com>

	* hostio.c (HOSTIO_PATH_MAX): Define.
	(require_filename, handle_open, handle_unlink, handle_readlink):
	Use it.
---
 gdb/gdbserver/hostio.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index df94d31..031bb54 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -50,6 +50,14 @@ safe_fromhex (char a, int *nibble)
   return 0;
 }
 
+/* Filenames are hex encoded, so the maximum we can handle is half the
+   packet buffer size.  Cap to PATH_MAX, if it is shorter.  */
+#if !defined (PATH_MAX) || (PATH_MAX > (PBUFSIZ / 2))
+#  define HOSTIO_PATH_MAX (PBUFSIZ / 2)
+#else
+#  define HOSTIO_PATH_MAX PATH_MAX
+#endif
+
 static int
 require_filename (char **pp, char *filename)
 {
@@ -64,7 +72,7 @@ require_filename (char **pp, char *filename)
       int nib1, nib2;
 
       /* Don't allow overflow.  */
-      if (count >= PATH_MAX - 1)
+      if (count >= HOSTIO_PATH_MAX - 1)
 	return -1;
 
       if (safe_fromhex (p[0], &nib1)
@@ -266,7 +274,7 @@ fileio_open_flags_to_host (int fileio_open_flags, int *open_flags_p)
 static void
 handle_open (char *own_buf)
 {
-  char filename[PATH_MAX];
+  char filename[HOSTIO_PATH_MAX];
   char *p;
   int fileio_flags, mode, flags, fd;
   struct fd_list *new_fd;
@@ -442,7 +450,7 @@ handle_close (char *own_buf)
 static void
 handle_unlink (char *own_buf)
 {
-  char filename[PATH_MAX];
+  char filename[HOSTIO_PATH_MAX];
   char *p;
   int ret;
 
@@ -470,7 +478,7 @@ static void
 handle_readlink (char *own_buf, int *new_packet_len)
 {
 #if defined (HAVE_READLINK)
-  char filename[PATH_MAX], linkname[PATH_MAX];
+  char filename[HOSTIO_PATH_MAX], linkname[HOSTIO_PATH_MAX];
   char *p;
   int ret, bytes_sent;
 


  parent reply	other threads:[~2013-06-27 18:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 18:52 [PATCH 00/09] Import unistd and pathmax gnulib modules Pedro Alves
2013-06-27 18:52 ` [PATCH 5/9] Constify main.c:get_init_files Pedro Alves
2013-06-27 18:52 ` [PATCH 6/9] Reimplement DJGPP's .gdbinit -> gdb.ini renaming Pedro Alves
2013-06-27 18:52 ` [PATCH 3/9] Import the "unistd" gnulib module Pedro Alves
2013-06-27 18:52 ` [PATCH 4/9] Rely on gnulib's unistd.h replacement Pedro Alves
2013-06-28  9:05   ` Yao Qi
2013-06-28 17:44     ` Pedro Alves
2013-06-28 18:11       ` Pedro Alves
2013-06-27 18:52 ` [PATCH 1/9] Reimport gnulib from scratch Pedro Alves
2013-06-28  8:49   ` Yao Qi
2013-06-28  9:55     ` Pedro Alves
2013-06-28 12:10       ` Yao Qi
2013-06-28 12:28         ` Pedro Alves
2013-06-27 18:52 ` [PATCH 2/9] utils.c: pathconf call, check for _PC_PATH_MAX instead of HAVE_UNISTD_H Pedro Alves
2013-06-27 18:53 ` [PATCH 7/9] Import the "pathmax" gnulib module Pedro Alves
2013-06-27 18:53 ` [PATCH 8/9] Normalize on PATH_MAX instead of MAXPATHLEN throughout Pedro Alves
2013-06-28 15:21   ` Tom Tromey
2013-06-28 18:06     ` Pedro Alves
2013-06-28 19:08       ` Tom Tromey
2013-06-27 18:59 ` Pedro Alves [this message]
2013-06-28 15:43 ` [PATCH 00/09] Import unistd and pathmax gnulib modules Tom Tromey
2013-07-01 11:31 ` 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=20130627185304.6625.18112.stgit@brno.lan \
    --to=palves@redhat.com \
    --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