|
15 | 15 | #include "remote.h" |
16 | 16 | #include "trace2.h" |
17 | 17 | #include "odb.h" |
| 18 | +#include "transport.h" |
| 19 | +#include "url.h" |
18 | 20 |
|
19 | 21 | static struct { |
20 | 22 | enum bundle_list_heuristic heuristic; |
@@ -890,11 +892,59 @@ int fetch_bundle_uri(struct repository *r, const char *uri, |
890 | 892 | return result; |
891 | 893 | } |
892 | 894 |
|
| 895 | +/* protocol of 'uri', or "file" if it has none (bare/UNC/relative path) */ |
| 896 | +static void bundle_uri_protocol(const char *uri, struct strbuf *out) |
| 897 | +{ |
| 898 | + const char *p = uri; |
| 899 | + |
| 900 | + while (is_urlschemechar(p == uri, *p)) |
| 901 | + p++; |
| 902 | + strbuf_reset(out); |
| 903 | + if (p > uri && starts_with(p, "://")) |
| 904 | + strbuf_add(out, uri, p - uri); |
| 905 | + else |
| 906 | + strbuf_addstr(out, "file"); |
| 907 | +} |
| 908 | + |
| 909 | +/* Drop advertised URIs whose protocol is not allowed (see protocol.*.allow). */ |
| 910 | +static void sanitize_bundle_list(struct bundle_list *list) |
| 911 | +{ |
| 912 | + struct remote_bundle_info **skipped; |
| 913 | + size_t nr = 0, i; |
| 914 | + struct remote_bundle_info *info; |
| 915 | + struct hashmap_iter iter; |
| 916 | + struct strbuf proto = STRBUF_INIT; |
| 917 | + |
| 918 | + ALLOC_ARRAY(skipped, hashmap_get_size(&list->bundles)); |
| 919 | + hashmap_for_each_entry(&list->bundles, &iter, info, ent) { |
| 920 | + if (!info->uri) |
| 921 | + continue; |
| 922 | + bundle_uri_protocol(info->uri, &proto); |
| 923 | + /* advertised URIs are not user-provided */ |
| 924 | + if (!is_transport_allowed(proto.buf, 0)) { |
| 925 | + warning(_("skipping bundle URI '%s': protocol '%s' " |
| 926 | + "is not allowed"), info->uri, proto.buf); |
| 927 | + skipped[nr++] = info; |
| 928 | + } |
| 929 | + } |
| 930 | + strbuf_release(&proto); |
| 931 | + |
| 932 | + for (i = 0; i < nr; i++) { |
| 933 | + hashmap_remove(&list->bundles, &skipped[i]->ent, NULL); |
| 934 | + clear_remote_bundle_info(skipped[i], NULL); |
| 935 | + free(skipped[i]); |
| 936 | + } |
| 937 | + |
| 938 | + free(skipped); |
| 939 | +} |
| 940 | + |
893 | 941 | int fetch_bundle_list(struct repository *r, struct bundle_list *list) |
894 | 942 | { |
895 | 943 | int result; |
896 | 944 | struct bundle_list global_list; |
897 | 945 |
|
| 946 | + sanitize_bundle_list(list); |
| 947 | + |
898 | 948 | /* |
899 | 949 | * If the creationToken heuristic is used, then the URIs |
900 | 950 | * advertised by 'list' are not nested lists and instead |
|
0 commit comments