|
|
| version 1.168, 2008/07/22 13:11:38 | version 1.169, 2009/01/12 07:09:08 |
|---|---|
| Line 639 static void _append(Request& r, MethodPa | Line 639 static void _append(Request& r, MethodPa |
| static void _base64(Request& r, MethodParams& params) { | static void _base64(Request& r, MethodParams& params) { |
| if(params.count()) { | if(params.count()) { |
| // decode | // decode: ^string:base64[encoded] |
| const char* cstr=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr(); | const char* cstr=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr(); |
| char* decoded_cstr=0; | char* decoded=0; |
| size_t decoded_size=0; | size_t length=0; |
| pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size); | pa_base64_decode(cstr, strlen(cstr), decoded, length); |
| if(decoded_cstr && decoded_size) | if(decoded && length){ |
| r.write_assign_lang(*new String(decoded_cstr, decoded_size, true)); | if(memchr((const char*)decoded, 0, length)) |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "Invalid \\x00 character found while decode to string. Decode it to file instead."); | |
| fix_line_breaks(decoded, length); | |
| if(length){ | |
| r.write_assign_lang(*new String(decoded, length, true/*tainted*/)); | |
| } | |
| } | |
| } else { | } else { |
| // encode | // encode: ^str.base64[] |
| VString& self=GET_SELF(r, VString); | VString& self=GET_SELF(r, VString); |
| const char* cstr=self.string().cstr(); | const char* cstr=self.string().cstr(); |
| const char* encoded=pa_base64_encode(cstr, strlen(cstr)); | const char* encoded=pa_base64_encode(cstr, strlen(cstr)); |
| r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/)); | r.write_assign_lang(*new String(encoded, 0, true/*tainted. once ?param=base64(something) was needed*/)); |
| } | } |
| } | } |