| 1 |
Description: w: Set array bound for tty |
| 2 |
There is no guarantee that the length of whatever |
| 3 |
sd_session_get_tty() returns is going to be under UT_LINESIZE |
| 4 |
so copying until strlen of the source string could be an issue. |
| 5 |
. |
| 6 |
Instead copy at most UT_LINESIZE-1 characters and break if the |
| 7 |
source string is at '\0' |
| 8 |
Author: Werner Fink <[email protected]> |
| 9 |
Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/241cb88542c862a4e682fb64884b4c993c176554 |
| 10 |
Applied-Upstream: 4.0.5 |
| 11 |
Last-Update: 2025-04-14 |
| 12 |
--- |
| 13 |
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ |
| 14 |
--- a/src/w.c |
| 15 |
+++ b/src/w.c |
| 16 |
@@ -546,12 +546,15 @@ |
| 17 |
char *sd_tty; |
| 18 |
|
| 19 |
if (sd_session_get_tty(session, &sd_tty) >= 0) { |
| 20 |
- for (i = 0; i < strlen (sd_tty); i++) |
| 21 |
+ for (i = 0; i < UT_LINESIZE; i++) { |
| 22 |
+ if (sd_tty[i] == '\0') break; |
| 23 |
+ |
| 24 |
/* clean up tty if garbled */ |
| 25 |
if (isalnum(sd_tty[i]) || (sd_tty[i] == '/')) |
| 26 |
tty[i + 5] = sd_tty[i]; |
| 27 |
else |
| 28 |
tty[i + 5] = '\0'; |
| 29 |
+ } |
| 30 |
free(sd_tty); |
| 31 |
} |
| 32 |
} else { |