serve: drop "keys" strvec
We collect the set of capabilities the client sends us in a strvec. While this is usually small, there's no limit to the number of capabilities the client can send us (e.g., they could just send us "agent" pkt-lines over and over, and we'd keep adding them to the list). Since all code has been converted away from using this list, let's get rid of it. This avoids a potential attack where clients waste our memory. Note that we do have to replace it with a flag, because some of the flush-packet logic checks whether we've seen any valid commands or keys. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 15, 2021 at 14:35 UTC
f0a35c9ce52ade69311ab3b8cb111e145eb7b875
1 file changed
+3
-5
serve.c
+3
-5
@@ -239,7 +239,7 @@ static int process_request(void)
239
{
240
enum request_state state = PROCESS_REQUEST_KEYS;
241
struct packet_reader reader;
242
- struct strvec keys = STRVEC_INIT;
242
+ int seen_capability_or_command = 0;
243
struct protocol_capability *command = NULL;
244
245
packet_reader_init(&reader, 0, NULL, 0,
@@ -260,10 +260,9 @@ static int process_request(void)
260
case PACKET_READ_EOF:
261
BUG("Should have already died when seeing EOF");
262
case PACKET_READ_NORMAL:
263
- /* collect request; a sequence of keys and values */
263
if (parse_command(reader.line, &command) ||
264
receive_client_capability(reader.line))
266
- strvec_push(&keys, reader.line);
265
+ seen_capability_or_command = 1;
266
else
267
die("unknown capability '%s'", reader.line);
268
@@ -275,7 +274,7 @@ static int process_request(void)
274
* If no command and no keys were given then the client
275
* wanted to terminate the connection.
276
*/
278
- if (!keys.nr)
277
+ if (!seen_capability_or_command)
278
return 1;
279
280
/*
@@ -309,7 +308,6 @@ static int process_request(void)
308
309
command->command(the_repository, &reader);
310
312
- strvec_clear(&keys);
311
return 0;
312
}
313