refs.c: off-by-one fix.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 15, 2005 at 18:52 UTC
06bf6ac4248e834a229027908d405f5e42ac96d7
1 file changed
+5
-2
refs.c
+5
-2
@@ -346,8 +346,11 @@ int check_ref_format(const char *ref)
346
if (level < 2)
347
return -1; /* at least of form "heads/blah" */
348
349
- /* do not allow ref name to end in "HEAD" */
350
- if (cp - ref > 4 && !strcmp(cp - 4, "HEAD"))
349
+ /* Do not allow ref name to end in "HEAD"
350
+ * Note that cp is poiting at one past NUL at the end.
351
+ * i.e. cp[-1] = NUL.
352
+ */
353
+ if (5 <= cp - ref && !strcmp(cp - 5, "HEAD"))
354
return -1;
355
356
return 0;