-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanitize process name for GUI notification helper
As it turns out, the process name field /proc/PID/stat can contain arbitrary characters. This is a problem, because we call a notification helper, usually notify-send, using system(). Aggressively strip all non-alphanumeric characters to fix a shell code injection vulnerability. Users who do not use GUI notifications (-n or -N) are not affected.
- Loading branch information
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/* sanitize replaces everything in string "s" that is not [a-zA-Z0-9] | ||
* with an underscore. The resulting string is safe to pass to a shell. | ||
*/ | ||
void sanitize(char* s) | ||
{ | ||
char c; | ||
for (int i = 0; s[i] != 0; i++) { | ||
c = s[i]; | ||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) { | ||
continue; | ||
} | ||
s[i] = '_'; | ||
} | ||
} |