Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug: Null byte in shell history causes segfault during $historywords reverse subscripting
- X-seq: zsh-workers 51826
- From: Jun T <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Bug: Null byte in shell history causes segfault during $historywords reverse subscripting
- Date: Mon, 5 Jun 2023 16:11:19 +0900
- Archived-at: <https://zsh.org/workers/51826>
- In-reply-to: <CAAikoAL0hiooRDJu=JdPqfQH_kZV+O-+D1iETKrV5JF3oNRiCA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAAikoAL0hiooRDJu=JdPqfQH_kZV+O-+D1iETKrV5JF3oNRiCA@mail.gmail.com>
> 2023/05/27 4:37, Eric Freese <ericdfreese@xxxxxxxxx> wrote:
>
> I've come across a segfault when shell history has been loaded from a
> file and contains a command where a null byte was entered into the
> line editor via ^V^@ (opposed to typing as $'\0'). Reverse
> subscripting $historywords on a pattern that does not match triggers
> the error.
Is this enough?
diff --git a/Src/hist.c b/Src/hist.c
index 7e6394406..e2b4b0b22 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -3796,8 +3796,14 @@ histsplitwords(char *lineptr, short **wordsp, int *nwordsp, int *nwordposp,
zrealloc(words, nwords*sizeof(*words));
}
words[nwordpos++] = lineptr - start;
- while (*lineptr && !inblank(*lineptr))
- lineptr++;
+ while (*lineptr) {
+ if (*lineptr == Meta && lineptr[1])
+ lineptr += 2;
+ else if (!inblank(*lineptr))
+ lineptr++;
+ else
+ break;
+ }
words[nwordpos++] = lineptr - start;
}
} while (*lineptr);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author