Re: [PATCH 3/3] improved validation of entry type in mktree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Josh Micich <josh.micich@xxxxxxxxx> writes:

> diff --git a/builtin-mktree.c b/builtin-mktree.c
> index a56c917..a37954a 100644
> --- a/builtin-mktree.c
> +++ b/builtin-mktree.c
> @@ -71,7 +71,7 @@ static void mktree_line(char *buf, size_t len, int 
> line_termination, int allow_m
>  {
>  	char *ptr, *ntr;
>  	unsigned mode;
> -	enum object_type type;
> +	enum object_type mode_type;

Why?

> @@ -94,29 +94,37 @@ static void mktree_line(char *buf, size_t len, int 
> line_termination, int allow_m
>  	if (S_ISGITLINK(mode))
>  		allow_missing = 1;
>  
> -	if (!allow_missing)
> -		type = sha1_object_info(sha1, NULL);
> -	else
> -		type = object_type(mode);
> -
> -	if (type < 0)
> -		die("object %s unavailable", sha1_to_hex(sha1));
>  
>  	*ntr++ = 0; /* now at the beginning of SHA1 */
> -	if (type != type_from_string(ptr))
> -		die("object type %s mismatch (%s)", ptr, typename(type));
>  
>  	path = ntr + 41;  /* at the beginning of name */
> +	struct strbuf p_uq = STRBUF_INIT;
>  	if (line_termination && path[0] == '"') {
> -		struct strbuf p_uq = STRBUF_INIT;

Why make its lifetime longer even though you do not use it outside of this
block?

> ...
>  	}

> +
> +	mode_type = object_type(mode);
> +	if (mode_type != type_from_string(ptr)) {
> +		die("entry '%s' object type (%s) doesn't match mode type (%s)", 
> path, ptr, typename(mode_type));
> +	}
> +
> +	enum object_type obj_type = sha1_object_info(sha1, NULL);
> +	if (obj_type < 0) {
> +		if (!allow_missing) {

This is the other way around; when allow_missing is given you shouldn't
even consult the object database to read it.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]