receive-pack: use find_commit_header() in check_cert_push_options()
Use the public function find_commit_header() instead of find_header() to simplify the code. This is possible and safe because we're operating on a strbuf, which is always NUL-terminated, so there is no risk of running over the end of the buffer. It cannot contain NUL within the buffer, as it is built using strbuf_addstr(), only. The string comparison becomes more complicated because we need to check for NUL explicitly after comparing the length-limited option, but on the flip side we don't need to clean up allocations or track the remaining buffer length. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
		
				
					committed by
					
						
						Junio C Hamano
					
				
			
			
				
	
			
			
			
						parent
						
							3526e67d91
						
					
				
				
					commit
					f51d790b67
				
			@ -718,35 +718,29 @@ leave:
 | 
				
			|||||||
static int check_cert_push_options(const struct string_list *push_options)
 | 
					static int check_cert_push_options(const struct string_list *push_options)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char *buf = push_cert.buf;
 | 
						const char *buf = push_cert.buf;
 | 
				
			||||||
	int len = push_cert.len;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char *option;
 | 
						const char *option;
 | 
				
			||||||
	const char *next_line;
 | 
						size_t optionlen;
 | 
				
			||||||
	int options_seen = 0;
 | 
						int options_seen = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int retval = 1;
 | 
						int retval = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!len)
 | 
						if (!*buf)
 | 
				
			||||||
		return 1;
 | 
							return 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while ((option = find_header(buf, len, "push-option", &next_line))) {
 | 
						while ((option = find_commit_header(buf, "push-option", &optionlen))) {
 | 
				
			||||||
		len -= (next_line - buf);
 | 
							buf = option + optionlen + 1;
 | 
				
			||||||
		buf = next_line;
 | 
					 | 
				
			||||||
		options_seen++;
 | 
							options_seen++;
 | 
				
			||||||
		if (options_seen > push_options->nr
 | 
							if (options_seen > push_options->nr
 | 
				
			||||||
		    || strcmp(option,
 | 
							    || strncmp(push_options->items[options_seen - 1].string,
 | 
				
			||||||
			      push_options->items[options_seen - 1].string)) {
 | 
								       option, optionlen)
 | 
				
			||||||
			retval = 0;
 | 
							    || push_options->items[options_seen - 1].string[optionlen])
 | 
				
			||||||
			goto leave;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		free(option);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (options_seen != push_options->nr)
 | 
						if (options_seen != push_options->nr)
 | 
				
			||||||
		retval = 0;
 | 
							retval = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
leave:
 | 
					 | 
				
			||||||
	free(option);
 | 
					 | 
				
			||||||
	return retval;
 | 
						return retval;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user