PATCH: overflow check in isreallycom

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
---
 Src/exec.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index 95291130ee..98cbb1f609 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1006,13 +1006,15 @@ isreallycom(Cmdnam cn)
     char fullnam[MAXCMDLEN];
 
     if (cn->node.flags & HASHED)
-	strcpy(fullnam, cn->u.cmd);
+	if (snprintf(fullnam, sizeof(fullnam), "%s", cn->u.cmd)
+		>= (int)sizeof(fullnam))
+	    return 0;
     else if (!cn->u.name)
 	return 0;
     else {
-	strcpy(fullnam, *(cn->u.name));
-	strcat(fullnam, "/");
-	strcat(fullnam, cn->node.nam);
+	if (snprintf(fullnam, sizeof(fullnam), "%s/%s",
+		    *(cn->u.name), cn->node.nam) >= (int)sizeof(fullnam))
+	    return 0;
     }
     return iscom(fullnam);
 }
-- 
2.38.1
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.