Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1 | From 5088d3b38775f8ac12d7f77636775b16059b67ef Mon Sep 17 00:00:00 2001 |
| 2 | From: Jeff King <peff@peff.net> |
| 3 | Date: Tue, 22 Sep 2015 18:03:49 -0400 |
| 4 | Subject: [PATCH] transport: refactor protocol whitelist code |
| 5 | |
| 6 | The current callers only want to die when their transport is |
| 7 | prohibited. But future callers want to query the mechanism |
| 8 | without dying. |
| 9 | |
| 10 | Let's break out a few query functions, and also save the |
| 11 | results in a static list so we don't have to re-parse for |
| 12 | each query. |
| 13 | |
| 14 | Based-on-a-patch-by: Blake Burkhart <bburky@bburky.com> |
| 15 | Signed-off-by: Jeff King <peff@peff.net> |
| 16 | Signed-off-by: Junio C Hamano <gitster@pobox.com> |
| 17 | |
| 18 | Upstream-Status: Backport |
| 19 | |
| 20 | http://archive.ubuntu.com/ubuntu/pool/main/g/git/git_2.5.0-1ubuntu0.1.debian.tar.xz |
| 21 | |
| 22 | CVE: CVE-2015-7545 #3 |
| 23 | Singed-off-by: Armin Kuster <akuster@mvista.com> |
| 24 | |
| 25 | --- |
| 26 | transport.c | 38 ++++++++++++++++++++++++++++++-------- |
| 27 | transport.h | 15 +++++++++++++-- |
| 28 | 2 files changed, 43 insertions(+), 10 deletions(-) |
| 29 | |
| 30 | Index: git-2.5.0/transport.c |
| 31 | =================================================================== |
| 32 | --- git-2.5.0.orig/transport.c 2015-12-11 12:47:09.547784038 -0500 |
| 33 | +++ git-2.5.0/transport.c 2015-12-11 12:47:09.543784009 -0500 |
| 34 | @@ -912,18 +912,40 @@ |
| 35 | return strchr(url, ':') - url; |
| 36 | } |
| 37 | |
| 38 | -void transport_check_allowed(const char *type) |
| 39 | +static const struct string_list *protocol_whitelist(void) |
| 40 | { |
| 41 | - struct string_list allowed = STRING_LIST_INIT_DUP; |
| 42 | - const char *v = getenv("GIT_ALLOW_PROTOCOL"); |
| 43 | + static int enabled = -1; |
| 44 | + static struct string_list allowed = STRING_LIST_INIT_DUP; |
| 45 | + |
| 46 | + if (enabled < 0) { |
| 47 | + const char *v = getenv("GIT_ALLOW_PROTOCOL"); |
| 48 | + if (v) { |
| 49 | + string_list_split(&allowed, v, ':', -1); |
| 50 | + string_list_sort(&allowed); |
| 51 | + enabled = 1; |
| 52 | + } else { |
| 53 | + enabled = 0; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return enabled ? &allowed : NULL; |
| 58 | +} |
| 59 | |
| 60 | - if (!v) |
| 61 | - return; |
| 62 | +int is_transport_allowed(const char *type) |
| 63 | +{ |
| 64 | + const struct string_list *allowed = protocol_whitelist(); |
| 65 | + return !allowed || string_list_has_string(allowed, type); |
| 66 | +} |
| 67 | |
| 68 | - string_list_split(&allowed, v, ':', -1); |
| 69 | - if (!unsorted_string_list_has_string(&allowed, type)) |
| 70 | +void transport_check_allowed(const char *type) |
| 71 | +{ |
| 72 | + if (!is_transport_allowed(type)) |
| 73 | die("transport '%s' not allowed", type); |
| 74 | - string_list_clear(&allowed, 0); |
| 75 | +} |
| 76 | + |
| 77 | +int transport_restrict_protocols(void) |
| 78 | +{ |
| 79 | + return !!protocol_whitelist(); |
| 80 | } |
| 81 | |
| 82 | struct transport *transport_get(struct remote *remote, const char *url) |
| 83 | Index: git-2.5.0/transport.h |
| 84 | =================================================================== |
| 85 | --- git-2.5.0.orig/transport.h 2015-12-11 12:47:09.547784038 -0500 |
| 86 | +++ git-2.5.0/transport.h 2015-12-11 12:47:09.543784009 -0500 |
| 87 | @@ -134,12 +134,23 @@ |
| 88 | struct transport *transport_get(struct remote *, const char *); |
| 89 | |
| 90 | /* |
| 91 | + * Check whether a transport is allowed by the environment. Type should |
| 92 | + * generally be the URL scheme, as described in Documentation/git.txt |
| 93 | + */ |
| 94 | +int is_transport_allowed(const char *type); |
| 95 | + |
| 96 | +/* |
| 97 | * Check whether a transport is allowed by the environment, |
| 98 | - * and die otherwise. type should generally be the URL scheme, |
| 99 | - * as described in Documentation/git.txt |
| 100 | + * and die otherwise. |
| 101 | */ |
| 102 | void transport_check_allowed(const char *type); |
| 103 | |
| 104 | +/* |
| 105 | + * Returns true if the user has attempted to turn on protocol |
| 106 | + * restrictions at all. |
| 107 | + */ |
| 108 | +int transport_restrict_protocols(void); |
| 109 | + |
| 110 | /* Transport options which apply to git:// and scp-style URLs */ |
| 111 | |
| 112 | /* The program to use on the remote side to send a pack */ |