git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/7] bisect: replace hardcoded "bad|good" by variables

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jun 11, 2015, 15:27 UTC
Message-ID
<vpq1thi465i.fsf@anie.imag.fr>
In-Reply-To
<1433953472-32572-2-git-send-email-antoine.delaite@ensimag.grenoble-inp.fr>
Antoine Delaite <antoine.delaite@ensimag.grenoble-inp.fr> writes:
> -	if (!strcmp(refname, "bad")) {
> +	char good_prefix[256];
> +	strcpy(good_prefix, name_good);
> +	strcat(good_prefix, "-");

You are silently adding a restriction here: name_good must be small enough to fit in a 256-bytes array. It's not a terrible restriction, but what may happen if you break it is a real issue.

Either you have to enforce this restriction somewhere, or you should not have the restriction at all. I'd vote for the second. strbuf is your friend here.

Show 8 quoted lines
> @@ -259,21 +264,21 @@ bisect_state() {
>  
>  bisect_next_check() {
>  	missing_good= missing_bad=
> -	git show-ref -q --verify refs/bisect/bad || missing_bad=t
> -	test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
> +	git show-ref -q --verify refs/bisect/$NAME_BAD || missing_bad=t
> +	test -n "$(git for-each-ref "refs/bisect/$NAME_GOOD-*")" || missing_good=t

There are other restrictions here: $NAME_BAD must be an acceptable ref name, and you're not quoting $NAME_BAD hence it must not contain shell meta-characters (The requirements for ref names almost imply that, but 'foo/bar{a,b}' is accepted and will trigger some expansion if your /bin/sh is bash for example).

Being an acceptable ref name is a constraint you have to check (Junio already mentionned check-ref-format). I think quoting variables makes sense too.

Show 6 quoted lines
> @@ -421,7 +426,7 @@ bisect_replay () {
>  		start)
>  			cmd="bisect_start $rev"
>  			eval "$cmd" ;;
> -		good|bad|skip)
> +		$NAME_GOOD|$NAME_BAD|skip)

$NAME_GOOD and $NAME_BAD need quoting if you're not sure they don't contain shell metacharacters.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Antoine DelaiteNext: Antoine Delaite
Message 3 of 9 in “bisect : correction of typo”
  1. 1/7 bisect : correction of typoAntoine Delaite, Jun 10, 2015
  2. 2/7 bisect: replace hardcoded "bad|good" by variablesAntoine Delaite, Jun 10, 2015
  3. Matthieu MoyJun 11, 2015
  4. 2/7 bisect: replace hardcoded "bad|good" by variablesAntoine Delaite, Jun 22, 2015
  5. Matthieu MoyJun 22, 2015
  6. 3/7 bisect: simplify the addition of new bisect termsAntoine Delaite, Jun 10, 2015
  7. 4/7 bisect: add the terms old/newAntoine Delaite, Jun 10, 2015
  8. Junio C HamanoJun 10, 2015
  9. Louis-Alexandre StuberJun 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.