File: sanitize.c

package info (click to toggle)
earlyoom 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 204 kB
  • sloc: ansic: 718; makefile: 82; sh: 71
file content (16 lines) | stat: -rw-r--r-- 422 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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] = '_';
    }
}