diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2011-07-26 12:25:17 +0200 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2011-07-26 12:25:17 +0200 |
commit | 1a51e3db1af215ffd65ab2347baead7b1179ad80 (patch) | |
tree | a90d0a88304f7654ea494ba0fe6aa4307ef5d691 /apt-pkg/contrib | |
parent | 822b344dacd3154df859ce6dbb1cb713ed96fc44 (diff) | |
parent | 27b16a2ed9a5cfdde955a0a49cd2fd73edce09c8 (diff) |
merged from debian-sid
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/sha1.cc | 5 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 61 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 4 |
4 files changed, 70 insertions, 4 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 821e6d688..e25caf1a5 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -258,7 +258,9 @@ string FindMountPointForDevice(const char *devnode) if(TokSplitString(' ', buf, out, 10)) { fclose(f); - return string(out[1]); + // unescape the \0XXX chars in the path + string mount_point = out[1]; + return DeEscapeString(mount_point); } } } diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc index eae52d52f..abc2aaf9f 100644 --- a/apt-pkg/contrib/sha1.cc +++ b/apt-pkg/contrib/sha1.cc @@ -74,10 +74,9 @@ static void SHA1Transform(uint32_t state[5],uint8_t const buffer[64]) uint32_t l[16]; } CHAR64LONG16; - CHAR64LONG16 *block; + CHAR64LONG16 workspace, *block; - uint8_t workspace[64]; - block = (CHAR64LONG16 *)workspace; + block = &workspace; memcpy(block,buffer,sizeof(workspace)); /* Copy context->state[] to working vars */ diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 072dda3ac..ab2da2d9a 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1240,7 +1240,68 @@ bool CheckDomainList(const string &Host,const string &List) return false; } /*}}}*/ +// DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string DeEscapeString(const string &input) +{ + char tmp[3]; + string::const_iterator it, escape_start; + string output, octal, hex; + for (it = input.begin(); it != input.end(); it++) + { + // just copy non-escape chars + if (*it != '\\') + { + output += *it; + continue; + } + // deal with double escape + if (*it == '\\' && + (it + 1 < input.end()) && it[1] == '\\') + { + // copy + output += *it; + // advance iterator one step further + it += 1; + continue; + } + + // ensure we have a char to read + if (it + 1 == input.end()) + continue; + + // read it + it++; + switch (*it) + { + case '0': + if (it + 2 <= input.end()) { + tmp[0] = it[1]; + tmp[1] = it[2]; + tmp[2] = 0; + output += (char)strtol(tmp, 0, 8); + it += 2; + } + break; + case 'x': + if (it + 2 <= input.end()) { + tmp[0] = it[1]; + tmp[1] = it[2]; + tmp[2] = 0; + output += (char)strtol(tmp, 0, 16); + it += 2; + } + break; + default: + // FIXME: raise exception here? + break; + } + } + return output; +} + /*}}}*/ // URI::CopyFrom - Copy from an object /*{{{*/ // --------------------------------------------------------------------- /* This parses the URI into all of its components */ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 89cbf0370..fba85cf94 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -39,6 +39,10 @@ bool ParseCWord(const char *&String,string &Res); string QuoteString(const string &Str,const char *Bad); string DeQuoteString(const string &Str); string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end); + +// unescape (\0XX and \xXX) from a string +string DeEscapeString(const string &input); + string SizeToStr(double Bytes); string TimeToStr(unsigned long Sec); string Base64Encode(const string &Str); |