diff --git a/daemon/bencode.c b/daemon/bencode.c index bd019913e..e6d1ae2be 100644 --- a/daemon/bencode.c +++ b/daemon/bencode.c @@ -709,7 +709,7 @@ static int __bencode_string(const char *s, int offset, int len) { unsigned long long sl; char *end; - for (pos = offset + 1; s[pos] != 0x3a && isdigit(s[pos]) && pos < len; ++pos); + for (pos = offset + 1; s[pos] != ':' && isdigit(s[pos]) && pos < len; ++pos); if (pos == len) return -1; @@ -726,24 +726,24 @@ static int __bencode_string(const char *s, int offset, int len) { static int __bencode_integer(const char *s, int offset, int len) { int pos; - if (s[offset + 1] == 0x2d) { - if (offset + 3 < len && s[offset + 2] == 0x30 && s[offset + 3] == 0x65) { + if (s[offset + 1] == '-') { + if (offset + 3 < len && s[offset + 2] == '0' && s[offset + 3] == 'e') { return -2; } ++offset; } - if (s[offset + 1] == 0x65) + if (s[offset + 1] == 'e') return -2; - if (s[offset + 1] == 0x30) { - if (offset + 2 < len && s[offset + 2] == 0x65) + if (s[offset + 1] == '0') { + if (offset + 2 < len && s[offset + 2] == 'e') return offset + 3; return -2; } - for (pos = offset + 1; s[pos] != 0x65 && pos < len; ++pos) { - if (s[pos] < 0x30 || s[pos] > 0x39) + for (pos = offset + 1; s[pos] != 'e' && pos < len; ++pos) { + if (s[pos] < '0' || s[pos] > '9') return -2; } @@ -756,7 +756,7 @@ static int __bencode_integer(const char *s, int offset, int len) { static int __bencode_next(const char *s, int offset, int len); static int __bencode_list(const char *s, int offset, int len) { - for (++offset; s[offset] != 0x65 && offset < len;) { + for (++offset; s[offset] != 'e' && offset < len;) { offset = __bencode_next(s, offset, len); if (offset < 0) return offset; @@ -769,7 +769,7 @@ static int __bencode_list(const char *s, int offset, int len) { } static int __bencode_dictionary(const char *s, int offset, int len) { - for (++offset; s[offset] != 0x65 && offset < len;) { + for (++offset; s[offset] != 'e' && offset < len;) { offset = __bencode_string(s, offset - 1, len); if (offset < 0) return offset; @@ -788,22 +788,22 @@ static int __bencode_next(const char *s, int offset, int len) { if (offset >= len) return -1; switch(s[offset]) { - case 0x69: + case 'i': return __bencode_integer(s, offset, len); - case 0x6c: + case 'l': return __bencode_list(s, offset, len); - case 0x64: + case 'd': return __bencode_dictionary(s, offset, len); - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - case 0x38: - case 0x39: + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': return __bencode_string(s, offset - 1, len); } return -2;