2 #include "object-store.h"
3 #include "repository.h"
16 #include "submodule-config.h"
20 static struct oidset gitmodules_found = OIDSET_INIT;
21 static struct oidset gitmodules_done = OIDSET_INIT;
26 #define FOREACH_MSG_ID(FUNC) \
28 FUNC(NUL_IN_HEADER, FATAL) \
29 FUNC(UNTERMINATED_HEADER, FATAL) \
31 FUNC(BAD_DATE, ERROR) \
32 FUNC(BAD_DATE_OVERFLOW, ERROR) \
33 FUNC(BAD_EMAIL, ERROR) \
34 FUNC(BAD_NAME, ERROR) \
35 FUNC(BAD_OBJECT_SHA1, ERROR) \
36 FUNC(BAD_PARENT_SHA1, ERROR) \
37 FUNC(BAD_TAG_OBJECT, ERROR) \
38 FUNC(BAD_TIMEZONE, ERROR) \
39 FUNC(BAD_TREE, ERROR) \
40 FUNC(BAD_TREE_SHA1, ERROR) \
41 FUNC(BAD_TYPE, ERROR) \
42 FUNC(DUPLICATE_ENTRIES, ERROR) \
43 FUNC(MISSING_AUTHOR, ERROR) \
44 FUNC(MISSING_COMMITTER, ERROR) \
45 FUNC(MISSING_EMAIL, ERROR) \
46 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
47 FUNC(MISSING_OBJECT, ERROR) \
48 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
49 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
50 FUNC(MISSING_TAG, ERROR) \
51 FUNC(MISSING_TAG_ENTRY, ERROR) \
52 FUNC(MISSING_TREE, ERROR) \
53 FUNC(MISSING_TREE_OBJECT, ERROR) \
54 FUNC(MISSING_TYPE, ERROR) \
55 FUNC(MISSING_TYPE_ENTRY, ERROR) \
56 FUNC(MULTIPLE_AUTHORS, ERROR) \
57 FUNC(TREE_NOT_SORTED, ERROR) \
58 FUNC(UNKNOWN_TYPE, ERROR) \
59 FUNC(ZERO_PADDED_DATE, ERROR) \
60 FUNC(GITMODULES_MISSING, ERROR) \
61 FUNC(GITMODULES_BLOB, ERROR) \
62 FUNC(GITMODULES_LARGE, ERROR) \
63 FUNC(GITMODULES_NAME, ERROR) \
64 FUNC(GITMODULES_SYMLINK, ERROR) \
65 FUNC(GITMODULES_URL, ERROR) \
66 FUNC(GITMODULES_PATH, ERROR) \
67 FUNC(GITMODULES_UPDATE, ERROR) \
69 FUNC(BAD_FILEMODE, WARN) \
70 FUNC(EMPTY_NAME, WARN) \
71 FUNC(FULL_PATHNAME, WARN) \
73 FUNC(HAS_DOTDOT, WARN) \
74 FUNC(HAS_DOTGIT, WARN) \
75 FUNC(NULL_SHA1, WARN) \
76 FUNC(ZERO_PADDED_FILEMODE, WARN) \
77 FUNC(NUL_IN_COMMIT, WARN) \
78 /* infos (reported as warnings, but ignored by default) */ \
79 FUNC(GITMODULES_PARSE, INFO) \
80 FUNC(BAD_TAG_NAME, INFO) \
81 FUNC(MISSING_TAGGER_ENTRY, INFO)
83 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
85 FOREACH_MSG_ID(MSG_ID)
91 #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
93 const char *id_string;
94 const char *downcased;
95 const char *camelcased;
97 } msg_id_info[FSCK_MSG_MAX + 1] = {
98 FOREACH_MSG_ID(MSG_ID)
99 { NULL, NULL, NULL, -1 }
103 static void prepare_msg_ids(void)
107 if (msg_id_info[0].downcased)
110 /* convert id_string to lower case, without underscores. */
111 for (i = 0; i < FSCK_MSG_MAX; i++) {
112 const char *p = msg_id_info[i].id_string;
114 char *q = xmalloc(len);
116 msg_id_info[i].downcased = q;
121 *(q)++ = tolower(*(p)++);
124 p = msg_id_info[i].id_string;
126 msg_id_info[i].camelcased = q;
133 *q++ = tolower(*p++);
140 static int parse_msg_id(const char *text)
146 for (i = 0; i < FSCK_MSG_MAX; i++)
147 if (!strcmp(text, msg_id_info[i].downcased))
153 void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
159 for (i = 0; i < FSCK_MSG_MAX; i++)
160 list_config_item(list, prefix, msg_id_info[i].camelcased);
163 static int fsck_msg_type(enum fsck_msg_id msg_id,
164 struct fsck_options *options)
168 assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
170 if (options->msg_type)
171 msg_type = options->msg_type[msg_id];
173 msg_type = msg_id_info[msg_id].msg_type;
174 if (options->strict && msg_type == FSCK_WARN)
175 msg_type = FSCK_ERROR;
181 static int parse_msg_type(const char *str)
183 if (!strcmp(str, "error"))
185 else if (!strcmp(str, "warn"))
187 else if (!strcmp(str, "ignore"))
190 die("Unknown fsck message type: '%s'", str);
193 int is_valid_msg_type(const char *msg_id, const char *msg_type)
195 if (parse_msg_id(msg_id) < 0)
197 parse_msg_type(msg_type);
201 void fsck_set_msg_type(struct fsck_options *options,
202 const char *msg_id, const char *msg_type)
204 int id = parse_msg_id(msg_id), type;
207 die("Unhandled message id: %s", msg_id);
208 type = parse_msg_type(msg_type);
210 if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
211 die("Cannot demote %s to %s", msg_id, msg_type);
213 if (!options->msg_type) {
216 ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
217 for (i = 0; i < FSCK_MSG_MAX; i++)
218 msg_type[i] = fsck_msg_type(i, options);
219 options->msg_type = msg_type;
222 options->msg_type[id] = type;
225 void fsck_set_msg_types(struct fsck_options *options, const char *values)
227 char *buf = xstrdup(values), *to_free = buf;
231 int len = strcspn(buf, " ,|"), equal;
241 equal < len && buf[equal] != '=' && buf[equal] != ':';
243 buf[equal] = tolower(buf[equal]);
246 if (!strcmp(buf, "skiplist")) {
248 die("skiplist requires a path");
249 oidset_parse_file(&options->skiplist, buf + equal + 1);
255 die("Missing '=': '%s'", buf);
257 fsck_set_msg_type(options, buf, buf + equal + 1);
263 static void append_msg_id(struct strbuf *sb, const char *msg_id)
266 char c = *(msg_id)++;
271 strbuf_addch(sb, tolower(c));
274 strbuf_addch(sb, *(msg_id)++);
278 strbuf_addstr(sb, ": ");
281 static int object_on_skiplist(struct fsck_options *opts,
282 const struct object_id *oid)
284 return opts && oid && oidset_contains(&opts->skiplist, oid);
287 __attribute__((format (printf, 5, 6)))
288 static int report(struct fsck_options *options,
289 const struct object_id *oid, enum object_type object_type,
290 enum fsck_msg_id id, const char *fmt, ...)
293 struct strbuf sb = STRBUF_INIT;
294 int msg_type = fsck_msg_type(id, options), result;
296 if (msg_type == FSCK_IGNORE)
299 if (object_on_skiplist(options, oid))
302 if (msg_type == FSCK_FATAL)
303 msg_type = FSCK_ERROR;
304 else if (msg_type == FSCK_INFO)
305 msg_type = FSCK_WARN;
307 append_msg_id(&sb, msg_id_info[id].id_string);
310 strbuf_vaddf(&sb, fmt, ap);
311 result = options->error_func(options, oid, object_type,
319 void fsck_enable_object_names(struct fsck_options *options)
321 if (!options->object_names)
322 options->object_names = kh_init_oid_map();
325 const char *fsck_get_object_name(struct fsck_options *options,
326 const struct object_id *oid)
329 if (!options->object_names)
331 pos = kh_get_oid_map(options->object_names, *oid);
332 if (pos >= kh_end(options->object_names))
334 return kh_value(options->object_names, pos);
337 void fsck_put_object_name(struct fsck_options *options,
338 const struct object_id *oid,
339 const char *fmt, ...)
342 struct strbuf buf = STRBUF_INIT;
346 if (!options->object_names)
349 pos = kh_put_oid_map(options->object_names, *oid, &hashret);
353 strbuf_vaddf(&buf, fmt, ap);
354 kh_value(options->object_names, pos) = strbuf_detach(&buf, NULL);
358 const char *fsck_describe_object(struct fsck_options *options,
359 const struct object_id *oid)
361 static struct strbuf bufs[] = {
362 STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
366 const char *name = fsck_get_object_name(options, oid);
369 b = (b + 1) % ARRAY_SIZE(bufs);
371 strbuf_addstr(buf, oid_to_hex(oid));
373 strbuf_addf(buf, " (%s)", name);
378 static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
380 struct tree_desc desc;
381 struct name_entry entry;
385 if (parse_tree(tree))
388 name = fsck_get_object_name(options, &tree->object.oid);
389 if (init_tree_desc_gently(&desc, tree->buffer, tree->size))
391 while (tree_entry_gently(&desc, &entry)) {
395 if (S_ISGITLINK(entry.mode))
398 if (S_ISDIR(entry.mode)) {
399 obj = (struct object *)lookup_tree(the_repository, &entry.oid);
401 fsck_put_object_name(options, &entry.oid, "%s%s/",
403 result = options->walk(obj, OBJ_TREE, data, options);
405 else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
406 obj = (struct object *)lookup_blob(the_repository, &entry.oid);
408 fsck_put_object_name(options, &entry.oid, "%s%s",
410 result = options->walk(obj, OBJ_BLOB, data, options);
413 result = error("in tree %s: entry %s has bad mode %.6o",
414 fsck_describe_object(options, &tree->object.oid),
415 entry.path, entry.mode);
425 static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options)
427 int counter = 0, generation = 0, name_prefix_len = 0;
428 struct commit_list *parents;
433 if (parse_commit(commit))
436 name = fsck_get_object_name(options, &commit->object.oid);
438 fsck_put_object_name(options, get_commit_tree_oid(commit),
441 result = options->walk((struct object *)get_commit_tree(commit),
442 OBJ_TREE, data, options);
447 parents = commit->parents;
448 if (name && parents) {
449 int len = strlen(name), power;
451 if (len && name[len - 1] == '^') {
453 name_prefix_len = len - 1;
455 else { /* parse ~<generation> suffix */
456 for (generation = 0, power = 1;
457 len && isdigit(name[len - 1]);
459 generation += power * (name[--len] - '0');
460 if (power > 1 && len && name[len - 1] == '~')
461 name_prefix_len = len - 1;
467 struct object_id *oid = &parents->item->object.oid;
470 fsck_put_object_name(options, oid, "%s^%d",
472 else if (generation > 0)
473 fsck_put_object_name(options, oid, "%.*s~%d",
474 name_prefix_len, name,
477 fsck_put_object_name(options, oid, "%s^", name);
479 result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options);
484 parents = parents->next;
489 static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
491 const char *name = fsck_get_object_name(options, &tag->object.oid);
496 fsck_put_object_name(options, &tag->tagged->oid, "%s", name);
497 return options->walk(tag->tagged, OBJ_ANY, data, options);
500 int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
505 if (obj->type == OBJ_NONE)
506 parse_object(the_repository, &obj->oid);
512 return fsck_walk_tree((struct tree *)obj, data, options);
514 return fsck_walk_commit((struct commit *)obj, data, options);
516 return fsck_walk_tag((struct tag *)obj, data, options);
518 error("Unknown object type for %s",
519 fsck_describe_object(options, &obj->oid));
525 * The entries in a tree are ordered in the _path_ order,
526 * which means that a directory entry is ordered by adding
527 * a slash to the end of it.
529 * So a directory called "a" is ordered _after_ a file
530 * called "a.c", because "a/" sorts after "a.c".
532 #define TREE_UNORDERED (-1)
533 #define TREE_HAS_DUPS (-2)
535 static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, const char *name2)
537 int len1 = strlen(name1);
538 int len2 = strlen(name2);
539 int len = len1 < len2 ? len1 : len2;
540 unsigned char c1, c2;
543 cmp = memcmp(name1, name2, len);
547 return TREE_UNORDERED;
550 * Ok, the first <len> characters are the same.
551 * Now we need to order the next one, but turn
552 * a '\0' into a '/' for a directory entry.
558 * git-write-tree used to write out a nonsense tree that has
559 * entries with the same name, one blob and one tree. Make
560 * sure we do not have duplicate entries.
562 return TREE_HAS_DUPS;
563 if (!c1 && S_ISDIR(mode1))
565 if (!c2 && S_ISDIR(mode2))
567 return c1 < c2 ? 0 : TREE_UNORDERED;
570 static int fsck_tree(const struct object_id *oid,
571 const char *buffer, unsigned long size,
572 struct fsck_options *options)
575 int has_null_sha1 = 0;
576 int has_full_path = 0;
577 int has_empty_name = 0;
581 int has_zero_pad = 0;
582 int has_bad_modes = 0;
583 int has_dup_entries = 0;
584 int not_properly_sorted = 0;
585 struct tree_desc desc;
589 if (init_tree_desc_gently(&desc, buffer, size)) {
590 retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
599 const char *name, *backslash;
600 const struct object_id *oid;
602 oid = tree_entry_extract(&desc, &name, &mode);
604 has_null_sha1 |= is_null_oid(oid);
605 has_full_path |= !!strchr(name, '/');
606 has_empty_name |= !*name;
607 has_dot |= !strcmp(name, ".");
608 has_dotdot |= !strcmp(name, "..");
609 has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
610 has_zero_pad |= *(char *)desc.buffer == '0';
612 if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
614 oidset_insert(&gitmodules_found, oid);
616 retval += report(options,
618 FSCK_MSG_GITMODULES_SYMLINK,
619 ".gitmodules is a symbolic link");
622 if ((backslash = strchr(name, '\\'))) {
625 has_dotgit |= is_ntfs_dotgit(backslash);
626 if (is_ntfs_dotgitmodules(backslash)) {
628 oidset_insert(&gitmodules_found, oid);
630 retval += report(options, oid, OBJ_TREE,
631 FSCK_MSG_GITMODULES_SYMLINK,
632 ".gitmodules is a symbolic link");
634 backslash = strchr(backslash, '\\');
638 if (update_tree_entry_gently(&desc)) {
639 retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
654 * This is nonstandard, but we had a few of these
655 * early on when we honored the full set of mode
659 if (!options->strict)
667 switch (verify_ordered(o_mode, o_name, mode, name)) {
669 not_properly_sorted = 1;
684 retval += report(options, oid, OBJ_TREE, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
686 retval += report(options, oid, OBJ_TREE, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
688 retval += report(options, oid, OBJ_TREE, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
690 retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOT, "contains '.'");
692 retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTDOT, "contains '..'");
694 retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
696 retval += report(options, oid, OBJ_TREE, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
698 retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
700 retval += report(options, oid, OBJ_TREE, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
701 if (not_properly_sorted)
702 retval += report(options, oid, OBJ_TREE, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
706 static int verify_headers(const void *data, unsigned long size,
707 const struct object_id *oid, enum object_type type,
708 struct fsck_options *options)
710 const char *buffer = (const char *)data;
713 for (i = 0; i < size; i++) {
716 return report(options, oid, type,
717 FSCK_MSG_NUL_IN_HEADER,
718 "unterminated header: NUL at offset %ld", i);
720 if (i + 1 < size && buffer[i + 1] == '\n')
726 * We did not find double-LF that separates the header
727 * and the body. Not having a body is not a crime but
728 * we do want to see the terminating LF for the last header
731 if (size && buffer[size - 1] == '\n')
734 return report(options, oid, type,
735 FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
738 static int fsck_ident(const char **ident,
739 const struct object_id *oid, enum object_type type,
740 struct fsck_options *options)
742 const char *p = *ident;
745 *ident = strchrnul(*ident, '\n');
750 return report(options, oid, type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
751 p += strcspn(p, "<>\n");
753 return report(options, oid, type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
755 return report(options, oid, type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
757 return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
759 p += strcspn(p, "<>\n");
761 return report(options, oid, type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
764 return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
766 if (*p == '0' && p[1] != ' ')
767 return report(options, oid, type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
768 if (date_overflows(parse_timestamp(p, &end, 10)))
769 return report(options, oid, type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
770 if ((end == p || *end != ' '))
771 return report(options, oid, type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
773 if ((*p != '+' && *p != '-') ||
779 return report(options, oid, type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
784 static int fsck_commit(const struct object_id *oid,
785 const char *buffer, unsigned long size,
786 struct fsck_options *options)
788 struct object_id tree_oid, parent_oid;
789 unsigned author_count;
791 const char *buffer_begin = buffer;
794 if (verify_headers(buffer, size, oid, OBJ_COMMIT, options))
797 if (!skip_prefix(buffer, "tree ", &buffer))
798 return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
799 if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
800 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
805 while (skip_prefix(buffer, "parent ", &buffer)) {
806 if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') {
807 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
814 while (skip_prefix(buffer, "author ", &buffer)) {
816 err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
820 if (author_count < 1)
821 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
822 else if (author_count > 1)
823 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
826 if (!skip_prefix(buffer, "committer ", &buffer))
827 return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
828 err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
831 if (memchr(buffer_begin, '\0', size)) {
832 err = report(options, oid, OBJ_COMMIT, FSCK_MSG_NUL_IN_COMMIT,
833 "NUL byte in the commit object body");
840 static int fsck_tag(const struct object_id *oid, const char *buffer,
841 unsigned long size, struct fsck_options *options)
843 struct object_id tagged_oid;
846 struct strbuf sb = STRBUF_INIT;
849 ret = verify_headers(buffer, size, oid, OBJ_TAG, options);
853 if (!skip_prefix(buffer, "object ", &buffer)) {
854 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
857 if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') {
858 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
864 if (!skip_prefix(buffer, "type ", &buffer)) {
865 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
868 eol = strchr(buffer, '\n');
870 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
873 if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
874 ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
879 if (!skip_prefix(buffer, "tag ", &buffer)) {
880 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
883 eol = strchr(buffer, '\n');
885 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
888 strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
889 if (check_refname_format(sb.buf, 0)) {
890 ret = report(options, oid, OBJ_TAG,
891 FSCK_MSG_BAD_TAG_NAME,
892 "invalid 'tag' name: %.*s",
893 (int)(eol - buffer), buffer);
899 if (!skip_prefix(buffer, "tagger ", &buffer)) {
900 /* early tags do not contain 'tagger' lines; warn only */
901 ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
906 ret = fsck_ident(&buffer, oid, OBJ_TAG, options);
913 struct fsck_gitmodules_data {
914 const struct object_id *oid;
915 struct fsck_options *options;
919 static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
921 struct fsck_gitmodules_data *data = vdata;
922 const char *subsection, *key;
926 if (parse_config_key(var, "submodule", &subsection, &subsection_len, &key) < 0 ||
930 name = xmemdupz(subsection, subsection_len);
931 if (check_submodule_name(name) < 0)
932 data->ret |= report(data->options,
934 FSCK_MSG_GITMODULES_NAME,
935 "disallowed submodule name: %s",
937 if (!strcmp(key, "url") && value &&
938 looks_like_command_line_option(value))
939 data->ret |= report(data->options,
941 FSCK_MSG_GITMODULES_URL,
942 "disallowed submodule url: %s",
944 if (!strcmp(key, "path") && value &&
945 looks_like_command_line_option(value))
946 data->ret |= report(data->options,
948 FSCK_MSG_GITMODULES_PATH,
949 "disallowed submodule path: %s",
951 if (!strcmp(key, "update") && value &&
952 parse_submodule_update_type(value) == SM_UPDATE_COMMAND)
953 data->ret |= report(data->options, data->oid, OBJ_BLOB,
954 FSCK_MSG_GITMODULES_UPDATE,
955 "disallowed submodule update setting: %s",
962 static int fsck_blob(const struct object_id *oid, const char *buf,
963 unsigned long size, struct fsck_options *options)
965 struct fsck_gitmodules_data data;
966 struct config_options config_opts = { 0 };
968 if (!oidset_contains(&gitmodules_found, oid))
970 oidset_insert(&gitmodules_done, oid);
972 if (object_on_skiplist(options, oid))
977 * A missing buffer here is a sign that the caller found the
978 * blob too gigantic to load into memory. Let's just consider
981 return report(options, oid, OBJ_BLOB,
982 FSCK_MSG_GITMODULES_LARGE,
983 ".gitmodules too large to parse");
987 data.options = options;
989 config_opts.error_action = CONFIG_ERROR_SILENT;
990 if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
991 ".gitmodules", buf, size, &data, &config_opts))
992 data.ret |= report(options, oid, OBJ_BLOB,
993 FSCK_MSG_GITMODULES_PARSE,
994 "could not parse gitmodules blob");
999 int fsck_object(struct object *obj, void *data, unsigned long size,
1000 struct fsck_options *options)
1003 return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
1005 if (obj->type == OBJ_BLOB)
1006 return fsck_blob(&obj->oid, data, size, options);
1007 if (obj->type == OBJ_TREE)
1008 return fsck_tree(&obj->oid, data, size, options);
1009 if (obj->type == OBJ_COMMIT)
1010 return fsck_commit(&obj->oid, data, size, options);
1011 if (obj->type == OBJ_TAG)
1012 return fsck_tag(&obj->oid, data, size, options);
1014 return report(options, &obj->oid, obj->type,
1015 FSCK_MSG_UNKNOWN_TYPE,
1016 "unknown type '%d' (internal fsck error)",
1020 int fsck_error_function(struct fsck_options *o,
1021 const struct object_id *oid,
1022 enum object_type object_type,
1023 int msg_type, const char *message)
1025 if (msg_type == FSCK_WARN) {
1026 warning("object %s: %s", fsck_describe_object(o, oid), message);
1029 error("object %s: %s", fsck_describe_object(o, oid), message);
1033 int fsck_finish(struct fsck_options *options)
1036 struct oidset_iter iter;
1037 const struct object_id *oid;
1039 oidset_iter_init(&gitmodules_found, &iter);
1040 while ((oid = oidset_iter_next(&iter))) {
1041 enum object_type type;
1045 if (oidset_contains(&gitmodules_done, oid))
1048 buf = read_object_file(oid, &type, &size);
1050 if (is_promisor_object(oid))
1052 ret |= report(options,
1054 FSCK_MSG_GITMODULES_MISSING,
1055 "unable to read .gitmodules blob");
1059 if (type == OBJ_BLOB)
1060 ret |= fsck_blob(oid, buf, size, options);
1062 ret |= report(options,
1064 FSCK_MSG_GITMODULES_BLOB,
1065 "non-blob found at .gitmodules");
1070 oidset_clear(&gitmodules_found);
1071 oidset_clear(&gitmodules_done);