public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Aleksander Ushakov <retes672@gmail.com>
Cc: dash@vger.kernel.org
Subject: [PATCH] expand: Use memmove when copying multi-byte chars in rmescapes
Date: Sun, 15 Mar 2026 21:45:08 +0900	[thread overview]
Message-ID: <abap1Nxtvh2bkoNM@gondor.apana.org.au> (raw)
In-Reply-To: <CADdNFauVF91SguPkBT7FUPuKLBbwTod=EeLAibqosujYRv01BQ@mail.gmail.com>

Aleksander Ushakov <retes672@gmail.com> wrote:
> Dear Dash maintainers,
> 
> I encountered a bug in Dash 0.5.13 and would like to report
> it. The behaviour is the same for ASAN error in Dash 0.5.12 and I
> reported it here (https://www.spinics.net/lists/dash/msg02856.html).
> So steps to reproduce are similarly for 0.5.12 and 0.5.13. The ASAN
> errors have some differences but the problem may be the same. The
> details are  provided below.
> 
> ==4385==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges
> [0x5e9360717719,0x5e936071771c) and [0x5e936071771b, 0x5e936071771e)
> overlap
>    #0 0x5e935fced469 in __asan_memcpy
> (/upstream/z/dash-0.5.13/src/dash+0xd6469) (BuildId:
> e987025fc7a0e719d6f6413a475e27117a9dee0e)
>    #1 0x5e935fd40db9 in _rmescapes /upstream/z/dash-0.5.13/src/expand.c:2129:8

Thanks for the report.  I'll change the memcpy to memmove.

---8<---
Use memmove instead of mempcpy in rmescapes as the two regions
can indeed overlap when escaps are removed in place.

Fixes: 990bbd15346d ("expand: Process multi-byte characters in subevalvar")
Reported-by: Aleksander Ushakov <retes672@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/expand.c b/src/expand.c
index eed8150..bbf8454 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -2128,7 +2128,8 @@ _rmescapes(char *str, int flag)
 				tail = 0;
 			}
 
-			q = mempcpy(q, p, ml);
+			memmove(q, p, ml);
+			q += ml;
 			p += ml + tail;
 			goto setnesc;
 		}
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2026-03-15 12:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-19 13:48 [BUG] memcpy-param-overlap _rmescapes src/expand.c:2129:8 Aleksander Ushakov
2026-03-15 12:45 ` Herbert Xu [this message]

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=abap1Nxtvh2bkoNM@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=retes672@gmail.com \
    /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