[PATCH] @{-<n>}: avoid crash with corrupt reflog
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 19, 2009, 12:41 UTC
- Message-ID
- <alpine.DEB.1.00.0901191338470.3586@pacific.mpi-cbg.de>
- In-Reply-To
- <7vljt7r9mq.fsf@gitster.siamese.dyndns.org>
The earlier code checked if a " to " was found after "checkout: Moving from ". However, it then went on to access the pointer to " to ", regardless if it was still NULL (if no " to " was found) or not.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> ---
You might want to squash this into "sha1_name: tweak @{-N}
lookup", just as a safety belt.sha1_name.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c index 9e5f444..853bac6 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -705,18 +705,18 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1, size_t len; int nth; - if (!prefixcmp(message, "checkout: moving from ")) { - match = message + strlen("checkout: moving from "); - if ((target = strstr(match, " to ")) != NULL) - target += 4; - } - - if (!match) + if (prefixcmp(message, "checkout: moving from ")) return 0; - len = target - match - 4; - if (target[len] == '\n' && !strncmp(match, target, len)) - return 0; + match = message + strlen("checkout: moving from "); + if ((target = strstr(match, " to ")) != NULL) { + len = target - match - 4; + target += 4; + if (target[len] == '\n' && !strncmp(match, target, len)) + return 0; + } + else + len = strchrnul(match, ' ') - match; nth = cb->cnt++ % cb->alloc; strbuf_reset(&cb->buf[nth]);
-- 1.6.1.347.g7b62749