summaryrefslogtreecommitdiff
path: root/udev_utils_string.c
diff options
context:
space:
mode:
authorScott James Remnant <scott@ubuntu.com>2007-05-16 20:00:29 +0200
committerKay Sievers <kay.sievers@vrfy.org>2007-05-16 20:00:29 +0200
commitca4f2c41b016530b5865b40b8dbbf0a3a0e8e634 (patch)
tree9e3ae46738390aba43ea9c7c08e80e38da0c09b3 /udev_utils_string.c
parent05610c088ee9ea668d4750f69a35bf833a63616d (diff)
replace_untrusted_chars: replace all whitespace with space
Diffstat (limited to 'udev_utils_string.c')
-rw-r--r--udev_utils_string.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/udev_utils_string.c b/udev_utils_string.c
index 38b91aa0bd..6f51aef014 100644
--- a/udev_utils_string.c
+++ b/udev_utils_string.c
@@ -229,15 +229,17 @@ int replace_untrusted_chars(char *str)
if ((str[i] >= '0' && str[i] <= '9') ||
(str[i] >= 'A' && str[i] <= 'Z') ||
(str[i] >= 'a' && str[i] <= 'z') ||
- strchr(" #$%+-./:=?@_,", str[i])) {
+ strchr("#$%+-./:=?@_,", str[i])) {
i++;
continue;
}
+
/* hex encoding */
if (str[i] == '\\' && str[i+1] == 'x') {
i += 2;
continue;
}
+
/* valid utf8 is accepted */
len = utf8_encoded_valid_unichar(&str[i]);
if (len > 1) {
@@ -245,6 +247,14 @@ int replace_untrusted_chars(char *str)
continue;
}
+ /* whitespace replaced with ordinary space */
+ if (isspace(str[i])) {
+ str[i] = ' ';
+ i++;
+ replaced++;
+ continue;
+ }
+
/* everything else is garbage */
str[i] = '_';
i++;