[PATCH] input: Fix potential out-of-bounds read in popstring

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
For an empty alias, the check on the last character of the alias in
popstring may read a bogus byte.  Fix this by checking whether the
alias is empty or not before reading the last byte.

Signed-off-by: Herbert Xu <[email protected]>
---
 src/input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/input.c b/src/input.c
index fb9858f..e56ab5f 100644
--- a/src/input.c
+++ b/src/input.c
@@ -401,7 +401,7 @@ static void popstring(void)
 	struct strpush *sp = parsefile->strpush;
 
 	INTOFF;
-	if (sp->ap) {
+	if (sp->ap && parsefile->nextc > sp->string) {
 		if (parsefile->nextc[-1] == ' ' ||
 		    parsefile->nextc[-1] == '\t') {
 			checkkwd |= CHKALIAS;
-- 
2.39.2

-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.