aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-03-09 11:54:45 -0500
committerNick Mathewson <nickm@torproject.org>2012-03-09 11:54:45 -0500
commitc13dc5170f09473ec2255501cbb1c0433bd959e5 (patch)
tree87f649e60f6b93b5eb017f649bd156e4d349fdbd /src
parent0f7e96038dcc003829c08fb511e274113471de3f (diff)
parent31f253ae6a96ea88425f8ea5c287f5eda599c9e9 (diff)
downloadtor-c13dc5170f09473ec2255501cbb1c0433bd959e5.tar.gz
tor-c13dc5170f09473ec2255501cbb1c0433bd959e5.zip
Merge remote-tracking branch 'origin/maint-0.2.2'
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 99af58a0ab..3950fc1695 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2347,14 +2347,16 @@ unescape_string(const char *s, char **result, size_t *size_out)
case '\"':
goto end_of_loop;
case '\\':
- if ((cp[1] == 'x' || cp[1] == 'X')
- && TOR_ISXDIGIT(cp[2]) && TOR_ISXDIGIT(cp[3])) {
+ if (cp[1] == 'x' || cp[1] == 'X') {
+ if (!(TOR_ISXDIGIT(cp[2]) && TOR_ISXDIGIT(cp[3])))
+ return NULL;
cp += 4;
} else if (TOR_ISODIGIT(cp[1])) {
cp += 2;
if (TOR_ISODIGIT(*cp)) ++cp;
if (TOR_ISODIGIT(*cp)) ++cp;
- } else if (cp[1]) {
+ } else if (cp[1] == 'n' || cp[1] == 'r' || cp[1] == 't' || cp[1] == '"'
+ || cp[1] == '\\' || cp[1] == '\'') {
cp += 2;
} else {
return NULL;
@@ -2386,9 +2388,19 @@ unescape_string(const char *s, char **result, size_t *size_out)
case 'r': *out++ = '\r'; cp += 2; break;
case 't': *out++ = '\t'; cp += 2; break;
case 'x': case 'X':
- *out++ = ((hex_decode_digit(cp[2])<<4) +
- hex_decode_digit(cp[3]));
- cp += 4;
+ {
+ int x1, x2;
+
+ x1 = hex_decode_digit(cp[2]);
+ x2 = hex_decode_digit(cp[3]);
+ if (x1 == -1 || x2 == -1) {
+ tor_free(*result);
+ return NULL;
+ }
+
+ *out++ = ((x1<<4) + x2);
+ cp += 4;
+ }
break;
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7':