File: w_array_bound_for_tty

package info (click to toggle)
procps 2%3A4.0.4-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,044 kB
  • sloc: ansic: 30,566; sh: 5,486; exp: 592; makefile: 562; sed: 16
file content (32 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 {