From e666e1156fba936dce93ccfa2486f67369a97129 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 28 Sep 2012 21:39:30 -0400 Subject: Handle octal escapes in /proc/self/mountinfo --- src/libutil/util.cc | 15 +++++++++++++++ src/libutil/util.hh | 6 ++++++ 2 files changed, 21 insertions(+) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 7f95d398147f..afb0dc0b2c07 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1101,6 +1101,21 @@ bool endOfList(std::istream & str) } +string decodeOctalEscaped(const string & s) +{ + string r; + for (string::const_iterator i = s.begin(); i != s.end(); ) { + if (*i != '\\') { r += *i++; continue; } + unsigned char c = 0; + ++i; + while (i != s.end() && *i >= '0' && *i < '8') + c = c * 8 + (*i++ - '0'); + r += c; + } + return r; +} + + void ignoreException() { try { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 408d99a96e66..d3861f730b63 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -332,6 +332,12 @@ string parseString(std::istream & str); bool endOfList(std::istream & str); +/* Escape a string that contains octal-encoded escape codes such as + used in /etc/fstab and /proc/mounts (e.g. "foo\040bar" decodes to + "foo bar"). */ +string decodeOctalEscaped(const string & s); + + /* Exception handling in destructors: print an error message, then ignore the exception. */ void ignoreException(); -- cgit 1.4.1