-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.cpp
52 lines (48 loc) · 1.07 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @brief AFL fuzz tester demonstration program
* @author Wolfram Rösler <[email protected]>
* @date 2017-05-24
*/
#include <fstream>
#include <iostream>
/**
* URI decoder.
* Translates %xx (xx = two hex digits) to the character with the
* appropriate ASCII code. Translates '+' into space. Leaves all
* other characters unchanged.
*
* Example:
* - In: "Hello+world%21"
* - Out: "Hello world!"
*
* @param s The string to decode.
* @returns The decoded string.
* @bug Buggy by design.
*/
const char *uridecode(const char *s) {
static char ret[100];
for(auto *p=ret;*s;++s) {
if (*s=='%') {
auto const a = *++s;
auto const b = *++s;
*p++ = (a<='9' ? a-'0' : a-'a') * 16 + (b<='9' ? b-'0' : b-'a');
} else if (*s=='+') {
*p++ = ' ';
} else {
*p++ = *s;
}
}
return ret;
}
/*
* Test program.
* Reads a pattern from stdin, decodes it, and writes the
* result to stdout.
*/
int main() {
auto const uri = std::string(
std::istreambuf_iterator<char>(std::cin),
std::istreambuf_iterator<char>()
);
std::cout << uridecode(uri.c_str());
}