Description: w: Set array bound for tty
 There is no guarantee that the length of whatever
 sd_session_get_tty() returns is going to be under UT_LINESIZE
 so copying until strlen of the source string could be an issue.
 .
 Instead copy at most UT_LINESIZE-1 characters and break if the
 source string is at '\0'
Author: Werner Fink <werner@suse.de>
Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/241cb88542c862a4e682fb64884b4c993c176554
Applied-Upstream: 4.0.5
Last-Update: 2025-04-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/w.c
+++ b/src/w.c
@@ -546,12 +546,15 @@
         char *sd_tty;
 
         if (sd_session_get_tty(session, &sd_tty) >= 0) {
-            for (i = 0; i < strlen (sd_tty); i++)
+           for (i = 0; i < UT_LINESIZE; i++) {
+               if (sd_tty[i] == '\0') break;
+
                 /* clean up tty if garbled */
 	        if (isalnum(sd_tty[i]) || (sd_tty[i] == '/'))
 		    tty[i + 5] = sd_tty[i];
 		else
 		    tty[i + 5] = '\0';
+            }
 	    free(sd_tty);
 	}
     } else {
