about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2023-10-10 23:46:15 +0200
committerOliver Kiddle <opk@zsh.org>2023-10-11 00:50:18 +0200
commit4878c2b1307d54cbdc218ee674403c03bc1e02c1 (patch)
treeb71f9901cd7119910bbd3496cab4e4d7171c2e75
parent83f8a71a7cc2137a1d4638228b3d83717c15af54 (diff)
downloadzsh-4878c2b1307d54cbdc218ee674403c03bc1e02c1.tar.gz
zsh-4878c2b1307d54cbdc218ee674403c03bc1e02c1.tar.xz
zsh-4878c2b1307d54cbdc218ee674403c03bc1e02c1.zip
52216: metafy usernames to allow for them to be UTF-8 encoded
-rw-r--r--ChangeLog3
-rw-r--r--Src/Modules/watch.c26
2 files changed, 21 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e0a94b10..9a5204ce7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2023-10-10  Oliver Kiddle  <opk@zsh.org>
 
+	* 52216: Src/Modules/watch.c: metafy usernames to allow for
+	them to be UTF-8 encoded
+
 	* 52214: Src/subst.c: allow extra byte for nul in allocation
 
 	* unposted (cf. 52166): Functions/Misc/run-help-svk:
diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c
index 0de8cbf9a..97d4fa608 100644
--- a/Src/Modules/watch.c
+++ b/Src/Modules/watch.c
@@ -423,20 +423,23 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
 /* See if the watch entry matches */
 
 static int
-watchlog_match(char *teststr, char *actual, int len)
+watchlog_match(char *teststr, char *actual, size_t buflen)
 {
     int ret = 0;
     Patprog pprog;
     char *str = dupstring(teststr);
+    int len = strnlen(actual, buflen);
+    char *user = metafy(actual, len,
+	    len == buflen ? META_HEAPDUP : META_USEHEAP);
 
     tokenize(str);
 
     if ((pprog = patcompile(str, PAT_STATIC, 0))) {
 	queue_signals();
-	if (pattry(pprog, actual))
+	if (pattry(pprog, user))
 	    ret = 1;
 	unqueue_signals();
-    } else if (!strncmp(actual, teststr, len))
+    } else if (!strcmp(user, teststr))
 	ret = 1;
     return ret;
 }
@@ -456,10 +459,17 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 	(void)watchlog2(inout, u, fmt, 1, 0);
 	return;
     }
-    if (*w && !strcmp(*w, "notme") &&
-	strncmp(u->ut_name, get_username(), sizeof(u->ut_name))) {
-	(void)watchlog2(inout, u, fmt, 1, 0);
-	return;
+    if (*w && !strcmp(*w, "notme")) {
+	int len = strnlen(u->ut_name, sizeof(u->ut_name));
+	char *username = metafy(u->ut_name, len,
+				(len == sizeof(u->ut_name) ?
+				 META_HEAPDUP /* allow for nul terminator */ :
+				 META_USEHEAP));
+	if (strcmp(username, get_username())) {
+	    (void)watchlog2(inout, u, fmt, 1, 0);
+	    return;
+	}
+	w++;
     }
     for (; *w; w++) {
 	bad = 0;
@@ -488,7 +498,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 		for (vv = ++v; *vv && *vv != '%'; vv++);
 		sav = *vv;
 		*vv = '\0';
-		if (!watchlog_match(v, u->ut_host, strlen(v)))
+		if (!watchlog_match(v, u->ut_host, sizeof(u->ut_host)))
 		    bad = 1;
 		*vv = sav;
 		v = vv;