public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Simon Marchi <simark@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdbserver/tracepoint.cc: use snprintf in gdb_agent_socket_init
Date: Tue, 14 Dec 2021 19:35:28 +0000 (GMT)	[thread overview]
Message-ID: <20211214193528.15B46385803B@sourceware.org> (raw)

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

commit 237f6eac1577223034a3e3436bd270428d097534
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Tue Dec 14 14:34:57 2021 -0500

    gdbserver/tracepoint.cc: use snprintf in gdb_agent_socket_init
    
    If we modify tracepoint.cc to try to use a too long unix socket name,
    for example by modifying SOCK_DIR to be:
    
        #define SOCK_DIR "/tmp/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut"
    
    ... trying to start an application with libinproctrace.so loaded
    crashes:
    
        $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6:./libinproctrace.so /bin/ls
        /home/smarchi/src/binutils-gdb/gdbserver/../gdbsupport/common-utils.cc:69: A problem internal to GDBserver in-process agent has been detected.
        xsnprintf: Assertion `ret < size' failed.
    
    Looking at the rest of the socket initialization code, the intent seems
    to be that if something goes wrong, we warn but let the program
    execute.  So crashing on this failed assertions seems against the intent.
    
    Commit 6cebaf6e1ae4 ("use xsnprintf instead of snprintf.") changed this
    code to use xsnprintf instead of snprintf, introducing this assertion.
    Before that, snprintf would return a value bigger that UNIX_PATH_MAX and
    the "if" after would catch it and emit a warning, which is exactly what
    we want.  That change was done because LynxOS didn't have snprintf.
    Since LynxOS isn't supported anymore, we can simply revert to use
    snprintf there.
    
    With this patch, we get a warning (printed by the caller of
    gdb_agent_socket_init), but the program keeps executing:
    
        $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6:./libinproctrace.so /bin/ls
        ipa: could not create sync socket
        ...
    
    Change-Id: I78bca52d5dc3145335abeae45a42052701e3f5dd

Diff:
---
 gdbserver/tracepoint.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index a62d9a7233c..97d8fa5877f 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -6943,8 +6943,8 @@ gdb_agent_socket_init (void)
 {
   int result, fd;
 
-  result = xsnprintf (agent_socket_name, UNIX_PATH_MAX, "%s/gdb_ust%d",
-		      SOCK_DIR, getpid ());
+  result = snprintf (agent_socket_name, UNIX_PATH_MAX, "%s/gdb_ust%d",
+		     SOCK_DIR, getpid ());
   if (result >= UNIX_PATH_MAX)
     {
       trace_debug ("string overflow allocating socket name");


                 reply	other threads:[~2021-12-14 19:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211214193528.15B46385803B@sourceware.org \
    --to=simark@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).