public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9325] d: Insert null terminator in obstack buffers
Date: Mon, 29 Nov 2021 00:28:11 +0000 (GMT)	[thread overview]
Message-ID: <20211129002811.1ED763858414@sourceware.org> (raw)

https://gcc.gnu.org/g:abd47b4abea7e1463706c1132dc78d468d27bd96

commit r11-9325-gabd47b4abea7e1463706c1132dc78d468d27bd96
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jul 26 17:06:08 2021 +0200

    d: Insert null terminator in obstack buffers
    
    Covers cases where functions that handle the extracted strings ignore
    the explicit length.  This isn't something that's known to happen in the
    current front-end, but the self-hosted front-end has been observed to do
    this in its conversions between D and C-style strings.
    
    gcc/d/ChangeLog:
    
            * d-lang.cc (deps_add_target): Insert null terminator in buffer.
            (deps_write): Likewise.
            (d_parse_file): Likewise.
    
    (cherry picked from commit b2abe4e1aded1409964b870899d18dfdb6384821)

Diff:
---
 gcc/d/d-lang.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 6ad3823d910..3e6566a3689 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -108,7 +108,7 @@ deps_add_target (const char *target, bool quoted)
 
   if (!quoted)
     {
-      obstack_grow (&buffer, target, strlen (target));
+      obstack_grow0 (&buffer, target, strlen (target));
       d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
       return;
     }
@@ -149,6 +149,7 @@ deps_add_target (const char *target, bool quoted)
       obstack_1grow (&buffer, *p);
     }
 
+  obstack_1grow (&buffer, '\0');
   d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
 }
 
@@ -278,6 +279,8 @@ deps_write (Module *module, obstack *buffer)
       obstack_grow (buffer, str, strlen (str));
       obstack_grow (buffer, ":\n", 2);
     }
+
+  obstack_1grow (buffer, '\0');
 }
 
 /* Implements the lang_hooks.init_options routine for language D.
@@ -884,6 +887,7 @@ d_parse_file (void)
 	      obstack_grow (&buffer, str, strlen (str));
 	    }
 
+	  obstack_1grow (&buffer, '\0');
 	  message ("%s", (char *) obstack_finish (&buffer));
 	}
     }


                 reply	other threads:[~2021-11-29  0:28 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=20211129002811.1ED763858414@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).