diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-03-12 22:22:16 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-03-12 22:22:21 +0100 |
commit | 7f110ff9b8828b477e87de7b28c708cf69a3d008 (patch) | |
tree | 651d0f8f32ce086872f1e262bb8caee795a04c67 /src/util.c | |
parent | man: reword tmpfiles selinux bits (diff) | |
download | systemd-7f110ff9b8828b477e87de7b28c708cf69a3d008.tar.xz systemd-7f110ff9b8828b477e87de7b28c708cf69a3d008.zip |
conf: enforce UTF8 validty everywhere
we need to make sure that configuration data we expose via the bus ends
up in using getting an assert(). Even though configuration data is only
parsed from trusted sources we should be more careful with what we read.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/util.c b/src/util.c index bf22f575c7..3a855c1be4 100644 --- a/src/util.c +++ b/src/util.c @@ -1833,7 +1833,8 @@ char *cunescape_length(const char *s, size_t length) { /* Undoes C style string escaping */ - if (!(r = new(char, length+1))) + r = new(char, length+1); + if (!r) return r; for (f = s, t = r; f < s + length; f++) { @@ -1887,8 +1888,10 @@ char *cunescape_length(const char *s, size_t length) { /* hexadecimal encoding */ int a, b; - if ((a = unhexchar(f[1])) < 0 || - (b = unhexchar(f[2])) < 0) { + a = unhexchar(f[1]); + b = unhexchar(f[2]); + + if (a < 0 || b < 0) { /* Invalid escape code, let's take it literal then */ *(t++) = '\\'; *(t++) = 'x'; @@ -1911,9 +1914,11 @@ char *cunescape_length(const char *s, size_t length) { /* octal encoding */ int a, b, c; - if ((a = unoctchar(f[0])) < 0 || - (b = unoctchar(f[1])) < 0 || - (c = unoctchar(f[2])) < 0) { + a = unoctchar(f[0]); + b = unoctchar(f[1]); + c = unoctchar(f[2]); + + if (a < 0 || b < 0 || c < 0) { /* Invalid escape code, let's take it literal then */ *(t++) = '\\'; *(t++) = f[0]; |