Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`



Add `dupstring()` fallback machanism to guard against NULL derefs
in 3-argument concat function.

Signed-off-by: Joey Pabalinas <joeypabalinas@xxxxxxxxx>

 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/Src/string.c b/Src/string.c
index 038624d65a9f533494..df7e932061dbfbaab2 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -126,9 +126,16 @@ mod_export char *
 zhtricat(char const *s1, char const *s2, char const *s3)
 {
     char *ptr;
-    size_t l1 = strlen(s1);
-    size_t l2 = strlen(s2);
+    size_t l1, l2;
 
+    /* String duplicate fallback to prevent NULL derefs */
+    if (!s1 && !s2)
+	return dupstring(s3);
+    if (!s1)
+	l1 = 0, s1 = s2;
+    else
+	l1 = strlen(s1);
+    l2 = strlen(s2);
     ptr = (char *)zhalloc(l1 + l2 + strlen(s3) + 1);
     strcpy(ptr, s1);
     strcpy(ptr + l1, s2);
-- 
2.15.1



Messages sorted by: Reverse Date, Date, Thread, Author