diff options
author | Sören Tempel <soeren+git@soeren-tempel.net> | 2022-02-08 22:29:30 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-01-05 18:26:49 +0300 |
commit | f15dfd86c4fba78881071dd0f5c63466fa9737a2 (patch) | |
tree | 058f2ba875aba98374fcceb3f5a2c55338401470 /editors | |
parent | 70f77e4617e06077231b8b63c3fb3406d7f8865d (diff) |
ed: don't use memcpy with overlapping memory regions
The memcpy invocations in the subCommand function, modified by this
commit, previously used memcpy with overlapping memory regions. This is
undefined behavior. On Alpine Linux, it causes BusyBox ed to crash since
we compile BusyBox with -D_FORTIFY_SOURCE=2 and our fortify-headers
implementation catches this source of undefined behavior [0]. The issue
can only be triggered if the replacement string is the same size or
shorter than the old string.
Looking at the code, it seems to me that a memmove(3) is what was
actually intended here, this commit modifies the code accordingly.
[0]: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13504
Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/ed.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/editors/ed.c b/editors/ed.c index 209ce9942..4a84f7433 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -720,7 +720,7 @@ static void subCommand(const char *cmd, int num1, int num2) if (deltaLen <= 0) { memcpy(&lp->data[offset], newStr, newLen); if (deltaLen) { - memcpy(&lp->data[offset + newLen], + memmove(&lp->data[offset + newLen], &lp->data[offset + oldLen], lp->len - offset - oldLen); |