public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ipa/112783] core dump on libxo when function is inlined
Date: Fri, 01 Dec 2023 23:53:55 +0000	[thread overview]
Message-ID: <bug-112783-4-rf7ZPdtYh7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112783-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112783

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is not in GCC but rather a bad assumption on the code part.

Basically we have:

memcpy(nbuf, name, nlen);
...


if (!name)
...


But the check after a memcpy can be removed as passing a null pointer to memcpy
is undefined even if nlen is 0 here.


This patch to the sources fixes the issue for me:
```
diff --git a/libxo/libxo.c b/libxo/libxo.c
index 916a111..ea71723 100644
--- a/libxo/libxo.c
+++ b/libxo/libxo.c
@@ -4300,7 +4300,8 @@ xo_format_value (xo_handle_t *xop, const char *name,
ssize_t nlen,
        if ((xsp->xs_flags & (XSF_EMIT | XSF_EMIT_KEY))
            || !(xsp->xs_flags & XSF_EMIT_LEAF_LIST)) {
            char nbuf[nlen + 1];
-           memcpy(nbuf, name, nlen);
+            if (name)
+             memcpy(nbuf, name, nlen);
            nbuf[nlen] = '\0';

            ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT_LEAF_LIST);
@@ -4324,7 +4325,8 @@ xo_format_value (xo_handle_t *xop, const char *name,
ssize_t nlen,

        } else if (!(xsp->xs_flags & XSF_EMIT_KEY)) {
            char nbuf[nlen + 1];
-           memcpy(nbuf, name, nlen);
+            if (name)
+             memcpy(nbuf, name, nlen);
            nbuf[nlen] = '\0';

            ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT);
@@ -4342,7 +4344,8 @@ xo_format_value (xo_handle_t *xop, const char *name,
ssize_t nlen,
        if ((xsp->xs_flags & XSF_EMIT_LEAF_LIST)
            || !(xsp->xs_flags & XSF_EMIT)) {
            char nbuf[nlen + 1];
-           memcpy(nbuf, name, nlen);
+            if (name)
+             memcpy(nbuf, name, nlen);
            nbuf[nlen] = '\0';

            ssize_t rc = xo_transition(xop, 0, nbuf, XSS_EMIT);

```

  parent reply	other threads:[~2023-12-01 23:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 13:32 [Bug ipa/112783] New: " yancheng.li at foxmail dot com
2023-12-01  5:06 ` [Bug ipa/112783] " sjames at gcc dot gnu.org
2023-12-01 23:33 ` pinskia at gcc dot gnu.org
2023-12-01 23:53 ` pinskia at gcc dot gnu.org [this message]
2023-12-12  3:40 ` yancheng.li at foxmail dot com
2023-12-12  3:45 ` pinskia at gcc dot gnu.org
2023-12-12  3:45 ` pinskia at gcc dot gnu.org
2023-12-15 21:09 ` cvs-commit at gcc dot gnu.org
2023-12-15 21:15 ` jvdelisle at gcc dot gnu.org
2024-01-05  3:09 ` jiangchuanganghw at outlook dot com
2024-01-05 14:38 ` xry111 at gcc dot gnu.org

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=bug-112783-4-rf7ZPdtYh7@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).