summaryrefslogtreecommitdiff
path: root/fsck.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2015-06-22 15:26:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-23 21:27:35 (GMT)
commite6826e335addb557dc80eebe46031f896ac4424c (patch)
tree54671e9cd4f2d50db94e040f78241f8b3b8377a0 /fsck.c
parent71ab8fa840fcca4b4f80acba6a529e3cbc174b65 (diff)
downloadgit-e6826e335addb557dc80eebe46031f896ac4424c.zip
git-e6826e335addb557dc80eebe46031f896ac4424c.tar.gz
git-e6826e335addb557dc80eebe46031f896ac4424c.tar.bz2
fsck: make fsck_ident() warn-friendly
When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fsck.c')
-rw-r--r--fsck.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/fsck.c b/fsck.c
index 4748f1e..8a6ecf3 100644
--- a/fsck.c
+++ b/fsck.c
@@ -482,40 +482,45 @@ static int require_end_of_header(const void *data, unsigned long size,
static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
{
+ const char *p = *ident;
char *end;
- if (**ident == '<')
+ *ident = strchrnul(*ident, '\n');
+ if (**ident == '\n')
+ (*ident)++;
+
+ if (*p == '<')
return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
- *ident += strcspn(*ident, "<>\n");
- if (**ident == '>')
+ p += strcspn(p, "<>\n");
+ if (*p == '>')
return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
- if (**ident != '<')
+ if (*p != '<')
return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
- if ((*ident)[-1] != ' ')
+ if (p[-1] != ' ')
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
- (*ident)++;
- *ident += strcspn(*ident, "<>\n");
- if (**ident != '>')
+ p++;
+ p += strcspn(p, "<>\n");
+ if (*p != '>')
return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
- (*ident)++;
- if (**ident != ' ')
+ p++;
+ if (*p != ' ')
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
- (*ident)++;
- if (**ident == '0' && (*ident)[1] != ' ')
+ p++;
+ if (*p == '0' && p[1] != ' ')
return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
- if (date_overflows(strtoul(*ident, &end, 10)))
+ if (date_overflows(strtoul(p, &end, 10)))
return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
- if (end == *ident || *end != ' ')
+ if ((end == p || *end != ' '))
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
- *ident = end + 1;
- if ((**ident != '+' && **ident != '-') ||
- !isdigit((*ident)[1]) ||
- !isdigit((*ident)[2]) ||
- !isdigit((*ident)[3]) ||
- !isdigit((*ident)[4]) ||
- ((*ident)[5] != '\n'))
+ p = end + 1;
+ if ((*p != '+' && *p != '-') ||
+ !isdigit(p[1]) ||
+ !isdigit(p[2]) ||
+ !isdigit(p[3]) ||
+ !isdigit(p[4]) ||
+ (p[5] != '\n'))
return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
- (*ident) += 6;
+ p += 6;
return 0;
}