From 9d29fc2e4bfba9fcd3b0944e683458a3f1fa0c47 Mon Sep 17 00:00:00 2001 From: Joseph Mingrone Date: Thu, 15 May 2025 11:42:14 -0300 Subject: [PATCH] sh: Avoid referencing uninitialized memory in alias If run as alias '' uninitialized memory could be referenced. This is based on a fix from NetBSD. For more information, refer to https://github.com/NetBSD/src/commit/10cfed82c28 . Obtained from: NetBSD (Robert Elz , 10cfed82c28) MFC after: 3 days Reported by: mckusick, Robert Elz Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D50364 --- bin/sh/alias.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/sh/alias.c b/bin/sh/alias.c index a02554d66e2..681e82b3e19 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -204,6 +204,11 @@ aliascmd(int argc __unused, char **argv __unused) return (0); } while ((n = *argptr++) != NULL) { + if (n[0] == '\0') { + warning("'': not found"); + ret = 1; + continue; + } if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */ if ((ap = lookupalias(n, 0)) == NULL) { warning("%s: not found", n);