--- trunk/jscoverage-server.c 2008/09/23 03:48:37 189 +++ trunk/jscoverage-server.c 2008/10/05 18:10:10 255 @@ -242,10 +242,10 @@ return c - '0'; } else if ('A' <= c && c <= 'F') { - return c - 'A'; + return c - 'A' + 10; } else if ('a' <= c && c <= 'f') { - return c - 'a'; + return c - 'a' + 10; } else { return 0; @@ -566,7 +566,7 @@ static int write_json(Coverage * coverage, const char * path) { /* write the JSON */ - FILE * f = fopen(path, "w"); + FILE * f = fopen(path, "wb"); if (f == NULL) { return -1; } @@ -630,7 +630,7 @@ struct stat buf; if (stat(path, &buf) == 0) { /* it exists: merge */ - FILE * f = fopen(path, "r"); + FILE * f = fopen(path, "rb"); if (f == NULL) { result = 1; } @@ -852,12 +852,10 @@ free(encoding); Stream_delete(input_stream); if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) { - free(characters); send_response(client_exchange, 502, "Encoding not supported\n"); goto done; } else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) { - free(characters); send_response(client_exchange, 502, "Error decoding response\n"); goto done; } @@ -933,22 +931,25 @@ /* add the `Server' response-header (RFC 2616 14.38, 3.8) */ HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION); + char * decoded_path = NULL; char * filesystem_path = NULL; const char * abs_path = HTTPExchange_get_abs_path(exchange); assert(*abs_path != '\0'); - if (str_starts_with(abs_path, "/jscoverage")) { + decoded_path = decode_uri_component(abs_path); + + if (str_starts_with(decoded_path, "/jscoverage")) { handle_jscoverage_request(exchange); goto done; } - if (strstr(abs_path, "..") != NULL) { + if (strstr(decoded_path, "..") != NULL) { send_response(exchange, 403, "Forbidden\n"); goto done; } - filesystem_path = make_path(document_root, abs_path + 1); + filesystem_path = make_path(document_root, decoded_path + 1); size_t filesystem_path_length = strlen(filesystem_path); if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') { /* stat on Windows doesn't work with trailing slash */ @@ -1052,6 +1053,7 @@ done: free(filesystem_path); + free(decoded_path); } static void handler(HTTPExchange * exchange) { @@ -1092,7 +1094,7 @@ else if (strcmp(argv[i], "--report-dir") == 0) { i++; if (i == argc) { - fatal("--report-dir: option requires an argument"); + fatal_command_line("--report-dir: option requires an argument"); } report_directory = argv[i]; } @@ -1103,7 +1105,7 @@ else if (strcmp(argv[i], "--document-root") == 0) { i++; if (i == argc) { - fatal("--document-root: option requires an argument"); + fatal_command_line("--document-root: option requires an argument"); } document_root = argv[i]; } @@ -1114,7 +1116,7 @@ else if (strcmp(argv[i], "--encoding") == 0) { i++; if (i == argc) { - fatal("--encoding: option requires an argument"); + fatal_command_line("--encoding: option requires an argument"); } jscoverage_encoding = argv[i]; } @@ -1125,7 +1127,7 @@ else if (strcmp(argv[i], "--ip-address") == 0) { i++; if (i == argc) { - fatal("--ip-address: option requires an argument"); + fatal_command_line("--ip-address: option requires an argument"); } ip_address = argv[i]; } @@ -1140,7 +1142,7 @@ else if (strcmp(argv[i], "--no-instrument") == 0) { i++; if (i == argc) { - fatal("--no-instrument: option requires an argument"); + fatal_command_line("--no-instrument: option requires an argument"); } no_instrument[num_no_instrument] = argv[i]; num_no_instrument++; @@ -1153,7 +1155,7 @@ else if (strcmp(argv[i], "--port") == 0) { i++; if (i == argc) { - fatal("--port: option requires an argument"); + fatal_command_line("--port: option requires an argument"); } port = argv[i]; } @@ -1170,10 +1172,10 @@ } else if (strncmp(argv[i], "-", 1) == 0) { - fatal("unrecognized option `%s'", argv[i]); + fatal_command_line("unrecognized option `%s'", argv[i]); } else { - fatal("too many arguments"); + fatal_command_line("too many arguments"); } } @@ -1181,10 +1183,10 @@ char * end; unsigned long numeric_port = strtoul(port, &end, 10); if (*end != '\0') { - fatal("--port: option must be an integer"); + fatal_command_line("--port: option must be an integer"); } if (numeric_port > UINT16_MAX) { - fatal("--port: option must be 16 bits"); + fatal_command_line("--port: option must be 16 bits"); } /* is this a shutdown? */