zsh-workers
 help / color / mirror / code / Atom feed
* Fix use after free warning in compmatch.c
@ 2022-10-04 17:53 Wesley Schwengle
  2022-10-04 17:53 ` [PATCH] Silence use-after-free " Wesley Schwengle
  0 siblings, 1 reply; 3+ messages in thread
From: Wesley Schwengle @ 2022-10-04 17:53 UTC (permalink / raw)
  To: zsh-workers

While compiling zsh from git on Debian with gcc 12.2.0 I came across the
following warning:

compmatch.c:2081:26: warning: pointer ‘or’ used after ‘realloc’ [-Wuse-after-free]

With the help of #zsh, with phy1729 and Mikachu in particular, it is solved
with the following patch.

If someone has a better solution to fix the warning, than this is merely a
notice of saying I got a warning while running make with the latest and
greatest zsh.

Cheers,
Wesley


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Silence use-after-free warning in compmatch.c
  2022-10-04 17:53 Fix use after free warning in compmatch.c Wesley Schwengle
@ 2022-10-04 17:53 ` Wesley Schwengle
  2022-10-17  4:18   ` Jun T
  0 siblings, 1 reply; 3+ messages in thread
From: Wesley Schwengle @ 2022-10-04 17:53 UTC (permalink / raw)
  To: zsh-workers

compmatch.c:2081:26: warning: pointer ‘or’ used after ‘realloc’ [-Wuse-after-free]

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
---
 Src/Zle/compmatch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index 56e5509a4..ddcecd589 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -2045,12 +2045,12 @@ join_strs(int la, char *sa, int lb, char *sb)
 				zlelineasstring(line, mp->llen, 0, &convlen,
 						NULL, 0);
 			    if (rr <= convlen) {
-				char *or = rs;
+				ptrdiff_t diff = rp - rs;
 				int alloclen = (convlen > 20) ? convlen : 20;
 
 				rs = realloc(rs, (rl += alloclen));
 				rr += alloclen;
-				rp += rs - or;
+				rp = rs + diff;
 			    }
 			    memcpy(rp, convstr, convlen);
 			    rp += convlen;
@@ -2073,11 +2073,11 @@ join_strs(int la, char *sa, int lb, char *sb)
 	} else {
 	    /* Same character, just take it. */
 	    if (rr <= 1 /* HERE charlen */) {
-		char *or = rs;
+		ptrdiff_t diff = rp - rs;
 
 		rs = realloc(rs, (rl += 20));
 		rr += 20;
-		rp += rs - or;
+		rp = rs + diff;
 	    }
 	    /* HERE: multibyte char */
 	    *rp++ = *sa;
-- 
2.38.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Silence use-after-free warning in compmatch.c
  2022-10-04 17:53 ` [PATCH] Silence use-after-free " Wesley Schwengle
@ 2022-10-17  4:18   ` Jun T
  0 siblings, 0 replies; 3+ messages in thread
From: Jun T @ 2022-10-17  4:18 UTC (permalink / raw)
  To: zsh-workers

I've pushed this patch.

> 2022/10/05 2:53, Wesley Schwengle <wesleys@opperschaap.net> wrote:
> 
> compmatch.c:2081:26: warning: pointer ‘or’ used after ‘realloc’ [-Wuse-after-free]
> 
> Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
> ---
> Src/Zle/compmatch.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
> index 56e5509a4..ddcecd589 100644
> --- a/Src/Zle/compmatch.c
> +++ b/Src/Zle/compmatch.c
(snip)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-17  4:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04 17:53 Fix use after free warning in compmatch.c Wesley Schwengle
2022-10-04 17:53 ` [PATCH] Silence use-after-free " Wesley Schwengle
2022-10-17  4:18   ` Jun T

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).