From 53362837009c78cd7a28e87924538d76e241edef Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 17 May 2024 02:59:08 +0000 Subject: [PATCH] When calling el_line make sure that we call the resizing function callback because el_line updates the legacy LineInfo structure and we need to notify that the cached copy of the the buffer has changed. Of course the resizing function can call el_line itself to update the buffer, so prevent recursion. Bug found by Peter Rufer at Arista. --- lib/libedit/el.h | 3 ++- lib/libedit/eln.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libedit/el.h b/lib/libedit/el.h index 757137839eb8..c50ecbd48234 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.46 2021/08/15 10:08:41 christos Exp $ */ +/* $NetBSD: el.h,v 1.47 2024/05/17 02:59:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -58,6 +58,7 @@ #define NARROW_HISTORY 0x040 #define NO_RESET 0x080 #define FIXIO 0x100 +#define FROM_ELLINE 0x200 typedef unsigned char el_action_t; /* Index to command array */ diff --git a/lib/libedit/eln.c b/lib/libedit/eln.c index 563ec2a672a9..660e1988cc26 100644 --- a/lib/libedit/eln.c +++ b/lib/libedit/eln.c @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.37 2022/01/11 18:30:15 christos Exp $ */ +/* $NetBSD: eln.c,v 1.38 2024/05/17 02:59:08 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.37 2022/01/11 18:30:15 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.38 2024/05/17 02:59:08 christos Exp $"); #endif /* not lint && not SCCSID */ #include @@ -365,6 +365,10 @@ el_line(EditLine *el) size_t offset; const wchar_t *p; + if (el->el_flags & FROM_ELLINE) + return info; + + el->el_flags |= FROM_ELLINE; info->buffer = ct_encode_string(winfo->buffer, &el->el_lgcyconv); offset = 0; @@ -377,6 +381,10 @@ el_line(EditLine *el) offset += ct_enc_width(*p); info->lastchar = info->buffer + offset; + if (el->el_chared.c_resizefun) + (*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg); + el->el_flags &= ~FROM_ELLINE; + return info; }