@matheusbsbs / matheus-bagliano / commits / dfab7c144e
Fork 0

use a hash of the lock token as the suffix for PUT/MOVE

After 753bc91 ("Remove the requirement opaquelocktoken uri scheme"), lock tokens are in the URI forms in which they are received from the server, eg. 'opaquelocktoken:', 'urn:uuid:'. However, "start_put" (and consequently "start_move"), which attempts to create a unique temporary file using the UUID of the lock token, inadvertently uses the lock token in its URI form. These file operations on the server may not be successful (specifically, in Windows), due to the colon ':' character from the URI form of the lock token in the file path. This patch uses a hash of the lock token instead, guaranteeing only "safe" characters (a-f, 0-9) are used in the file path. The token's hash is generated when the lock token is received from the server in handle_new_lock_ctx, minimizing the number of times of hashing. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Feb 14, 2009 at 17:52 UTC dfab7c144eb2f02fc1481173422ecc416a060155
2 files changed +18 -2
http-push.c
+11 -2
@@ -152,6 +152,7 @@ struct remote_lock
152 char *url;
153 char *owner;
154 char *token;
155 + char tmpfile_suffix[41];
156 time_t start_time;
157 long timeout;
158 int refreshing;
@@ -556,8 +557,7 @@ static void start_put(struct transfer_request *request)
557 request->dest = strbuf_detach(&buf, NULL);
558
559 append_remote_object_url(&buf, remote->url, hex, 0);
559 - strbuf_addstr(&buf, "_");
560 - strbuf_addstr(&buf, request->lock->token);
560 + strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
561 request->url = strbuf_detach(&buf, NULL);
562
563 slot = get_active_slot();
@@ -1129,6 +1129,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
1129 static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
1130 {
1131 struct remote_lock *lock = (struct remote_lock *)ctx->userData;
1132 + git_SHA_CTX sha_ctx;
1133 + unsigned char lock_token_sha1[20];
1134
1135 if (tag_closed && ctx->cdata) {
1136 if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
@@ -1141,6 +1143,13 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
1143 } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
1144 lock->token = xmalloc(strlen(ctx->cdata) + 1);
1145 strcpy(lock->token, ctx->cdata);
1146 +
1147 + git_SHA1_Init(&sha_ctx);
1148 + git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
1149 + git_SHA1_Final(lock_token_sha1, &sha_ctx);
1150 +
1151 + lock->tmpfile_suffix[0] = '_';
1152 + memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
1153 }
1154 }
1155 }
t/t5540-http-push.sh
+7
@@ -94,6 +94,13 @@ test_expect_success 'MKCOL sends directory names with trailing slashes' '
94
95 '
96
97 +test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
98 +
99 + grep -P "\"(?:PUT|MOVE) .+objects/[\da-z]{2}/[\da-z]{38}_[\da-z\-]{40} HTTP/[0-9.]+\" 20\d" \
100 + < "$HTTPD_ROOT_PATH"/access.log
101 +
102 +'
103 +
104 stop_httpd
105
106 test_done