| 307 | } |
| 308 | |
| 309 | static int download_https_uri_to_file(const char *file, const char *uri) |
| 310 | { |
| 311 | int result = 0; |
| 312 | struct child_process cp = CHILD_PROCESS_INIT; |
| 313 | FILE *child_in = NULL, *child_out = NULL; |
| 314 | struct strbuf line = STRBUF_INIT; |
| 315 | int found_get = 0; |
| 316 | |
| 317 | /* |
| 318 | * The protocol we speak with git-remote-https(1) uses a space to |
| 319 | * separate between URI and file, so the URI itself must not contain a |
| 320 | * space. If it did, an adversary could change the location where the |
| 321 | * downloaded file is being written to. |
| 322 | * |
| 323 | * Similarly, we use newlines to separate commands from one another. |
| 324 | * Consequently, neither the URI nor the file must contain a newline or |
| 325 | * otherwise an adversary could inject arbitrary commands. |
| 326 | * |
| 327 | * TODO: Restricting newlines in the target paths may break valid |
| 328 | * usecases, even if those are a bit more on the esoteric side. |
| 329 | * If this ever becomes a problem we should probably think about |
| 330 | * alternatives. One alternative could be to use NUL-delimited |
| 331 | * requests in git-remote-http(1). Another alternative could be |
| 332 | * to use URL quoting. |
| 333 | */ |
| 334 | if (strpbrk(uri, " \n")) |
| 335 | return error("bundle-uri: URI is malformed: '%s'", file); |
| 336 | if (strchr(file, '\n')) |
| 337 | return error("bundle-uri: filename is malformed: '%s'", file); |
| 338 | |
| 339 | strvec_pushl(&cp.args, "git-remote-https", uri, NULL); |
| 340 | cp.err = -1; |
| 341 | cp.in = -1; |
| 342 | cp.out = -1; |
| 343 | |
| 344 | if (start_command(&cp)) |
| 345 | return 1; |
| 346 | |
| 347 | child_in = fdopen(cp.in, "w"); |
| 348 | if (!child_in) { |
| 349 | result = 1; |
| 350 | goto cleanup; |
| 351 | } |
| 352 | |
| 353 | child_out = fdopen(cp.out, "r"); |
| 354 | if (!child_out) { |
| 355 | result = 1; |
| 356 | goto cleanup; |
| 357 | } |
| 358 | |
| 359 | fprintf(child_in, "capabilities\n"); |
| 360 | fflush(child_in); |
| 361 | |
| 362 | while (!strbuf_getline(&line, child_out)) { |
| 363 | if (!line.len) |
| 364 | break; |
| 365 | if (!strcmp(line.buf, "get")) |
| 366 | found_get = 1; |
no test coverage detected