Skip to content

Commit f0a35c9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab539c9 commit f0a35c9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

serve.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int process_request(void)
239239
{
240240
enum request_state state = PROCESS_REQUEST_KEYS;
241241
struct packet_reader reader;
242-
struct strvec keys = STRVEC_INIT;
242+
int seen_capability_or_command = 0;
243243
struct protocol_capability *command = NULL;
244244

245245
packet_reader_init(&reader, 0, NULL, 0,
@@ -260,10 +260,9 @@ static int process_request(void)
260260
case PACKET_READ_EOF:
261261
BUG("Should have already died when seeing EOF");
262262
case PACKET_READ_NORMAL:
263-
/* collect request; a sequence of keys and values */
264263
if (parse_command(reader.line, &command) ||
265264
receive_client_capability(reader.line))
266-
strvec_push(&keys, reader.line);
265+
seen_capability_or_command = 1;
267266
else
268267
die("unknown capability '%s'", reader.line);
269268

@@ -275,7 +274,7 @@ static int process_request(void)
275274
* If no command and no keys were given then the client
276275
* wanted to terminate the connection.
277276
*/
278-
if (!keys.nr)
277+
if (!seen_capability_or_command)
279278
return 1;
280279

281280
/*
@@ -309,7 +308,6 @@ static int process_request(void)
309308

310309
command->command(the_repository, &reader);
311310

312-
strvec_clear(&keys);
313311
return 0;
314312
}
315313

0 commit comments

Comments
 (0)