fsck.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. #include "cache.h"
  2. #include "object-store.h"
  3. #include "repository.h"
  4. #include "object.h"
  5. #include "blob.h"
  6. #include "tree.h"
  7. #include "tree-walk.h"
  8. #include "commit.h"
  9. #include "tag.h"
  10. #include "fsck.h"
  11. #include "refs.h"
  12. #include "url.h"
  13. #include "utf8.h"
  14. #include "decorate.h"
  15. #include "oidset.h"
  16. #include "packfile.h"
  17. #include "submodule-config.h"
  18. #include "config.h"
  19. #include "credential.h"
  20. #include "help.h"
  21. static struct oidset gitmodules_found = OIDSET_INIT;
  22. static struct oidset gitmodules_done = OIDSET_INIT;
  23. #define FSCK_FATAL -1
  24. #define FSCK_INFO -2
  25. #define FOREACH_MSG_ID(FUNC) \
  26. /* fatal errors */ \
  27. FUNC(NUL_IN_HEADER, FATAL) \
  28. FUNC(UNTERMINATED_HEADER, FATAL) \
  29. /* errors */ \
  30. FUNC(BAD_DATE, ERROR) \
  31. FUNC(BAD_DATE_OVERFLOW, ERROR) \
  32. FUNC(BAD_EMAIL, ERROR) \
  33. FUNC(BAD_NAME, ERROR) \
  34. FUNC(BAD_OBJECT_SHA1, ERROR) \
  35. FUNC(BAD_PARENT_SHA1, ERROR) \
  36. FUNC(BAD_TAG_OBJECT, ERROR) \
  37. FUNC(BAD_TIMEZONE, ERROR) \
  38. FUNC(BAD_TREE, ERROR) \
  39. FUNC(BAD_TREE_SHA1, ERROR) \
  40. FUNC(BAD_TYPE, ERROR) \
  41. FUNC(DUPLICATE_ENTRIES, ERROR) \
  42. FUNC(MISSING_AUTHOR, ERROR) \
  43. FUNC(MISSING_COMMITTER, ERROR) \
  44. FUNC(MISSING_EMAIL, ERROR) \
  45. FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
  46. FUNC(MISSING_OBJECT, ERROR) \
  47. FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
  48. FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
  49. FUNC(MISSING_TAG, ERROR) \
  50. FUNC(MISSING_TAG_ENTRY, ERROR) \
  51. FUNC(MISSING_TREE, ERROR) \
  52. FUNC(MISSING_TREE_OBJECT, ERROR) \
  53. FUNC(MISSING_TYPE, ERROR) \
  54. FUNC(MISSING_TYPE_ENTRY, ERROR) \
  55. FUNC(MULTIPLE_AUTHORS, ERROR) \
  56. FUNC(TREE_NOT_SORTED, ERROR) \
  57. FUNC(UNKNOWN_TYPE, ERROR) \
  58. FUNC(ZERO_PADDED_DATE, ERROR) \
  59. FUNC(GITMODULES_MISSING, ERROR) \
  60. FUNC(GITMODULES_BLOB, ERROR) \
  61. FUNC(GITMODULES_LARGE, ERROR) \
  62. FUNC(GITMODULES_NAME, ERROR) \
  63. FUNC(GITMODULES_SYMLINK, ERROR) \
  64. FUNC(GITMODULES_URL, ERROR) \
  65. FUNC(GITMODULES_PATH, ERROR) \
  66. FUNC(GITMODULES_UPDATE, ERROR) \
  67. /* warnings */ \
  68. FUNC(BAD_FILEMODE, WARN) \
  69. FUNC(EMPTY_NAME, WARN) \
  70. FUNC(FULL_PATHNAME, WARN) \
  71. FUNC(HAS_DOT, WARN) \
  72. FUNC(HAS_DOTDOT, WARN) \
  73. FUNC(HAS_DOTGIT, WARN) \
  74. FUNC(NULL_SHA1, WARN) \
  75. FUNC(ZERO_PADDED_FILEMODE, WARN) \
  76. FUNC(NUL_IN_COMMIT, WARN) \
  77. /* infos (reported as warnings, but ignored by default) */ \
  78. FUNC(GITMODULES_PARSE, INFO) \
  79. FUNC(BAD_TAG_NAME, INFO) \
  80. FUNC(MISSING_TAGGER_ENTRY, INFO)
  81. #define MSG_ID(id, msg_type) FSCK_MSG_##id,
  82. enum fsck_msg_id {
  83. FOREACH_MSG_ID(MSG_ID)
  84. FSCK_MSG_MAX
  85. };
  86. #undef MSG_ID
  87. #define STR(x) #x
  88. #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
  89. static struct {
  90. const char *id_string;
  91. const char *downcased;
  92. const char *camelcased;
  93. int msg_type;
  94. } msg_id_info[FSCK_MSG_MAX + 1] = {
  95. FOREACH_MSG_ID(MSG_ID)
  96. { NULL, NULL, NULL, -1 }
  97. };
  98. #undef MSG_ID
  99. static void prepare_msg_ids(void)
  100. {
  101. int i;
  102. if (msg_id_info[0].downcased)
  103. return;
  104. /* convert id_string to lower case, without underscores. */
  105. for (i = 0; i < FSCK_MSG_MAX; i++) {
  106. const char *p = msg_id_info[i].id_string;
  107. int len = strlen(p);
  108. char *q = xmalloc(len);
  109. msg_id_info[i].downcased = q;
  110. while (*p)
  111. if (*p == '_')
  112. p++;
  113. else
  114. *(q)++ = tolower(*(p)++);
  115. *q = '\0';
  116. p = msg_id_info[i].id_string;
  117. q = xmalloc(len);
  118. msg_id_info[i].camelcased = q;
  119. while (*p) {
  120. if (*p == '_') {
  121. p++;
  122. if (*p)
  123. *q++ = *p++;
  124. } else {
  125. *q++ = tolower(*p++);
  126. }
  127. }
  128. *q = '\0';
  129. }
  130. }
  131. static int parse_msg_id(const char *text)
  132. {
  133. int i;
  134. prepare_msg_ids();
  135. for (i = 0; i < FSCK_MSG_MAX; i++)
  136. if (!strcmp(text, msg_id_info[i].downcased))
  137. return i;
  138. return -1;
  139. }
  140. void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
  141. {
  142. int i;
  143. prepare_msg_ids();
  144. for (i = 0; i < FSCK_MSG_MAX; i++)
  145. list_config_item(list, prefix, msg_id_info[i].camelcased);
  146. }
  147. static int fsck_msg_type(enum fsck_msg_id msg_id,
  148. struct fsck_options *options)
  149. {
  150. int msg_type;
  151. assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
  152. if (options->msg_type)
  153. msg_type = options->msg_type[msg_id];
  154. else {
  155. msg_type = msg_id_info[msg_id].msg_type;
  156. if (options->strict && msg_type == FSCK_WARN)
  157. msg_type = FSCK_ERROR;
  158. }
  159. return msg_type;
  160. }
  161. static int parse_msg_type(const char *str)
  162. {
  163. if (!strcmp(str, "error"))
  164. return FSCK_ERROR;
  165. else if (!strcmp(str, "warn"))
  166. return FSCK_WARN;
  167. else if (!strcmp(str, "ignore"))
  168. return FSCK_IGNORE;
  169. else
  170. die("Unknown fsck message type: '%s'", str);
  171. }
  172. int is_valid_msg_type(const char *msg_id, const char *msg_type)
  173. {
  174. if (parse_msg_id(msg_id) < 0)
  175. return 0;
  176. parse_msg_type(msg_type);
  177. return 1;
  178. }
  179. void fsck_set_msg_type(struct fsck_options *options,
  180. const char *msg_id, const char *msg_type)
  181. {
  182. int id = parse_msg_id(msg_id), type;
  183. if (id < 0)
  184. die("Unhandled message id: %s", msg_id);
  185. type = parse_msg_type(msg_type);
  186. if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
  187. die("Cannot demote %s to %s", msg_id, msg_type);
  188. if (!options->msg_type) {
  189. int i;
  190. int *msg_type;
  191. ALLOC_ARRAY(msg_type, FSCK_MSG_MAX);
  192. for (i = 0; i < FSCK_MSG_MAX; i++)
  193. msg_type[i] = fsck_msg_type(i, options);
  194. options->msg_type = msg_type;
  195. }
  196. options->msg_type[id] = type;
  197. }
  198. void fsck_set_msg_types(struct fsck_options *options, const char *values)
  199. {
  200. char *buf = xstrdup(values), *to_free = buf;
  201. int done = 0;
  202. while (!done) {
  203. int len = strcspn(buf, " ,|"), equal;
  204. done = !buf[len];
  205. if (!len) {
  206. buf++;
  207. continue;
  208. }
  209. buf[len] = '\0';
  210. for (equal = 0;
  211. equal < len && buf[equal] != '=' && buf[equal] != ':';
  212. equal++)
  213. buf[equal] = tolower(buf[equal]);
  214. buf[equal] = '\0';
  215. if (!strcmp(buf, "skiplist")) {
  216. if (equal == len)
  217. die("skiplist requires a path");
  218. oidset_parse_file(&options->skiplist, buf + equal + 1);
  219. buf += len + 1;
  220. continue;
  221. }
  222. if (equal == len)
  223. die("Missing '=': '%s'", buf);
  224. fsck_set_msg_type(options, buf, buf + equal + 1);
  225. buf += len + 1;
  226. }
  227. free(to_free);
  228. }
  229. static void append_msg_id(struct strbuf *sb, const char *msg_id)
  230. {
  231. for (;;) {
  232. char c = *(msg_id)++;
  233. if (!c)
  234. break;
  235. if (c != '_')
  236. strbuf_addch(sb, tolower(c));
  237. else {
  238. assert(*msg_id);
  239. strbuf_addch(sb, *(msg_id)++);
  240. }
  241. }
  242. strbuf_addstr(sb, ": ");
  243. }
  244. static int object_on_skiplist(struct fsck_options *opts,
  245. const struct object_id *oid)
  246. {
  247. return opts && oid && oidset_contains(&opts->skiplist, oid);
  248. }
  249. __attribute__((format (printf, 5, 6)))
  250. static int report(struct fsck_options *options,
  251. const struct object_id *oid, enum object_type object_type,
  252. enum fsck_msg_id id, const char *fmt, ...)
  253. {
  254. va_list ap;
  255. struct strbuf sb = STRBUF_INIT;
  256. int msg_type = fsck_msg_type(id, options), result;
  257. if (msg_type == FSCK_IGNORE)
  258. return 0;
  259. if (object_on_skiplist(options, oid))
  260. return 0;
  261. if (msg_type == FSCK_FATAL)
  262. msg_type = FSCK_ERROR;
  263. else if (msg_type == FSCK_INFO)
  264. msg_type = FSCK_WARN;
  265. append_msg_id(&sb, msg_id_info[id].id_string);
  266. va_start(ap, fmt);
  267. strbuf_vaddf(&sb, fmt, ap);
  268. result = options->error_func(options, oid, object_type,
  269. msg_type, sb.buf);
  270. strbuf_release(&sb);
  271. va_end(ap);
  272. return result;
  273. }
  274. void fsck_enable_object_names(struct fsck_options *options)
  275. {
  276. if (!options->object_names)
  277. options->object_names = kh_init_oid_map();
  278. }
  279. const char *fsck_get_object_name(struct fsck_options *options,
  280. const struct object_id *oid)
  281. {
  282. khiter_t pos;
  283. if (!options->object_names)
  284. return NULL;
  285. pos = kh_get_oid_map(options->object_names, *oid);
  286. if (pos >= kh_end(options->object_names))
  287. return NULL;
  288. return kh_value(options->object_names, pos);
  289. }
  290. void fsck_put_object_name(struct fsck_options *options,
  291. const struct object_id *oid,
  292. const char *fmt, ...)
  293. {
  294. va_list ap;
  295. struct strbuf buf = STRBUF_INIT;
  296. khiter_t pos;
  297. int hashret;
  298. if (!options->object_names)
  299. return;
  300. pos = kh_put_oid_map(options->object_names, *oid, &hashret);
  301. if (!hashret)
  302. return;
  303. va_start(ap, fmt);
  304. strbuf_vaddf(&buf, fmt, ap);
  305. kh_value(options->object_names, pos) = strbuf_detach(&buf, NULL);
  306. va_end(ap);
  307. }
  308. const char *fsck_describe_object(struct fsck_options *options,
  309. const struct object_id *oid)
  310. {
  311. static struct strbuf bufs[] = {
  312. STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
  313. };
  314. static int b = 0;
  315. struct strbuf *buf;
  316. const char *name = fsck_get_object_name(options, oid);
  317. buf = bufs + b;
  318. b = (b + 1) % ARRAY_SIZE(bufs);
  319. strbuf_reset(buf);
  320. strbuf_addstr(buf, oid_to_hex(oid));
  321. if (name)
  322. strbuf_addf(buf, " (%s)", name);
  323. return buf->buf;
  324. }
  325. static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
  326. {
  327. struct tree_desc desc;
  328. struct name_entry entry;
  329. int res = 0;
  330. const char *name;
  331. if (parse_tree(tree))
  332. return -1;
  333. name = fsck_get_object_name(options, &tree->object.oid);
  334. if (init_tree_desc_gently(&desc, tree->buffer, tree->size))
  335. return -1;
  336. while (tree_entry_gently(&desc, &entry)) {
  337. struct object *obj;
  338. int result;
  339. if (S_ISGITLINK(entry.mode))
  340. continue;
  341. if (S_ISDIR(entry.mode)) {
  342. obj = (struct object *)lookup_tree(the_repository, &entry.oid);
  343. if (name && obj)
  344. fsck_put_object_name(options, &entry.oid, "%s%s/",
  345. name, entry.path);
  346. result = options->walk(obj, OBJ_TREE, data, options);
  347. }
  348. else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
  349. obj = (struct object *)lookup_blob(the_repository, &entry.oid);
  350. if (name && obj)
  351. fsck_put_object_name(options, &entry.oid, "%s%s",
  352. name, entry.path);
  353. result = options->walk(obj, OBJ_BLOB, data, options);
  354. }
  355. else {
  356. result = error("in tree %s: entry %s has bad mode %.6o",
  357. fsck_describe_object(options, &tree->object.oid),
  358. entry.path, entry.mode);
  359. }
  360. if (result < 0)
  361. return result;
  362. if (!res)
  363. res = result;
  364. }
  365. return res;
  366. }
  367. static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options)
  368. {
  369. int counter = 0, generation = 0, name_prefix_len = 0;
  370. struct commit_list *parents;
  371. int res;
  372. int result;
  373. const char *name;
  374. if (parse_commit(commit))
  375. return -1;
  376. name = fsck_get_object_name(options, &commit->object.oid);
  377. if (name)
  378. fsck_put_object_name(options, get_commit_tree_oid(commit),
  379. "%s:", name);
  380. result = options->walk((struct object *)get_commit_tree(commit),
  381. OBJ_TREE, data, options);
  382. if (result < 0)
  383. return result;
  384. res = result;
  385. parents = commit->parents;
  386. if (name && parents) {
  387. int len = strlen(name), power;
  388. if (len && name[len - 1] == '^') {
  389. generation = 1;
  390. name_prefix_len = len - 1;
  391. }
  392. else { /* parse ~<generation> suffix */
  393. for (generation = 0, power = 1;
  394. len && isdigit(name[len - 1]);
  395. power *= 10)
  396. generation += power * (name[--len] - '0');
  397. if (power > 1 && len && name[len - 1] == '~')
  398. name_prefix_len = len - 1;
  399. }
  400. }
  401. while (parents) {
  402. if (name) {
  403. struct object_id *oid = &parents->item->object.oid;
  404. if (counter++)
  405. fsck_put_object_name(options, oid, "%s^%d",
  406. name, counter);
  407. else if (generation > 0)
  408. fsck_put_object_name(options, oid, "%.*s~%d",
  409. name_prefix_len, name,
  410. generation + 1);
  411. else
  412. fsck_put_object_name(options, oid, "%s^", name);
  413. }
  414. result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options);
  415. if (result < 0)
  416. return result;
  417. if (!res)
  418. res = result;
  419. parents = parents->next;
  420. }
  421. return res;
  422. }
  423. static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
  424. {
  425. const char *name = fsck_get_object_name(options, &tag->object.oid);
  426. if (parse_tag(tag))
  427. return -1;
  428. if (name)
  429. fsck_put_object_name(options, &tag->tagged->oid, "%s", name);
  430. return options->walk(tag->tagged, OBJ_ANY, data, options);
  431. }
  432. int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
  433. {
  434. if (!obj)
  435. return -1;
  436. if (obj->type == OBJ_NONE)
  437. parse_object(the_repository, &obj->oid);
  438. switch (obj->type) {
  439. case OBJ_BLOB:
  440. return 0;
  441. case OBJ_TREE:
  442. return fsck_walk_tree((struct tree *)obj, data, options);
  443. case OBJ_COMMIT:
  444. return fsck_walk_commit((struct commit *)obj, data, options);
  445. case OBJ_TAG:
  446. return fsck_walk_tag((struct tag *)obj, data, options);
  447. default:
  448. error("Unknown object type for %s",
  449. fsck_describe_object(options, &obj->oid));
  450. return -1;
  451. }
  452. }
  453. struct name_stack {
  454. const char **names;
  455. size_t nr, alloc;
  456. };
  457. static void name_stack_push(struct name_stack *stack, const char *name)
  458. {
  459. ALLOC_GROW(stack->names, stack->nr + 1, stack->alloc);
  460. stack->names[stack->nr++] = name;
  461. }
  462. static const char *name_stack_pop(struct name_stack *stack)
  463. {
  464. return stack->nr ? stack->names[--stack->nr] : NULL;
  465. }
  466. static void name_stack_clear(struct name_stack *stack)
  467. {
  468. FREE_AND_NULL(stack->names);
  469. stack->nr = stack->alloc = 0;
  470. }
  471. /*
  472. * The entries in a tree are ordered in the _path_ order,
  473. * which means that a directory entry is ordered by adding
  474. * a slash to the end of it.
  475. *
  476. * So a directory called "a" is ordered _after_ a file
  477. * called "a.c", because "a/" sorts after "a.c".
  478. */
  479. #define TREE_UNORDERED (-1)
  480. #define TREE_HAS_DUPS (-2)
  481. static int is_less_than_slash(unsigned char c)
  482. {
  483. return '\0' < c && c < '/';
  484. }
  485. static int verify_ordered(unsigned mode1, const char *name1,
  486. unsigned mode2, const char *name2,
  487. struct name_stack *candidates)
  488. {
  489. int len1 = strlen(name1);
  490. int len2 = strlen(name2);
  491. int len = len1 < len2 ? len1 : len2;
  492. unsigned char c1, c2;
  493. int cmp;
  494. cmp = memcmp(name1, name2, len);
  495. if (cmp < 0)
  496. return 0;
  497. if (cmp > 0)
  498. return TREE_UNORDERED;
  499. /*
  500. * Ok, the first <len> characters are the same.
  501. * Now we need to order the next one, but turn
  502. * a '\0' into a '/' for a directory entry.
  503. */
  504. c1 = name1[len];
  505. c2 = name2[len];
  506. if (!c1 && !c2)
  507. /*
  508. * git-write-tree used to write out a nonsense tree that has
  509. * entries with the same name, one blob and one tree. Make
  510. * sure we do not have duplicate entries.
  511. */
  512. return TREE_HAS_DUPS;
  513. if (!c1 && S_ISDIR(mode1))
  514. c1 = '/';
  515. if (!c2 && S_ISDIR(mode2))
  516. c2 = '/';
  517. /*
  518. * There can be non-consecutive duplicates due to the implicitly
  519. * added slash, e.g.:
  520. *
  521. * foo
  522. * foo.bar
  523. * foo.bar.baz
  524. * foo.bar/
  525. * foo/
  526. *
  527. * Record non-directory candidates (like "foo" and "foo.bar" in
  528. * the example) on a stack and check directory candidates (like
  529. * foo/" and "foo.bar/") against that stack.
  530. */
  531. if (!c1 && is_less_than_slash(c2)) {
  532. name_stack_push(candidates, name1);
  533. } else if (c2 == '/' && is_less_than_slash(c1)) {
  534. for (;;) {
  535. const char *p;
  536. const char *f_name = name_stack_pop(candidates);
  537. if (!f_name)
  538. break;
  539. if (!skip_prefix(name2, f_name, &p))
  540. continue;
  541. if (!*p)
  542. return TREE_HAS_DUPS;
  543. if (is_less_than_slash(*p)) {
  544. name_stack_push(candidates, f_name);
  545. break;
  546. }
  547. }
  548. }
  549. return c1 < c2 ? 0 : TREE_UNORDERED;
  550. }
  551. static int fsck_tree(const struct object_id *oid,
  552. const char *buffer, unsigned long size,
  553. struct fsck_options *options)
  554. {
  555. int retval = 0;
  556. int has_null_sha1 = 0;
  557. int has_full_path = 0;
  558. int has_empty_name = 0;
  559. int has_dot = 0;
  560. int has_dotdot = 0;
  561. int has_dotgit = 0;
  562. int has_zero_pad = 0;
  563. int has_bad_modes = 0;
  564. int has_dup_entries = 0;
  565. int not_properly_sorted = 0;
  566. struct tree_desc desc;
  567. unsigned o_mode;
  568. const char *o_name;
  569. struct name_stack df_dup_candidates = { NULL };
  570. if (init_tree_desc_gently(&desc, buffer, size)) {
  571. retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
  572. return retval;
  573. }
  574. o_mode = 0;
  575. o_name = NULL;
  576. while (desc.size) {
  577. unsigned short mode;
  578. const char *name, *backslash;
  579. const struct object_id *oid;
  580. oid = tree_entry_extract(&desc, &name, &mode);
  581. has_null_sha1 |= is_null_oid(oid);
  582. has_full_path |= !!strchr(name, '/');
  583. has_empty_name |= !*name;
  584. has_dot |= !strcmp(name, ".");
  585. has_dotdot |= !strcmp(name, "..");
  586. has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
  587. has_zero_pad |= *(char *)desc.buffer == '0';
  588. if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
  589. if (!S_ISLNK(mode))
  590. oidset_insert(&gitmodules_found, oid);
  591. else
  592. retval += report(options,
  593. oid, OBJ_TREE,
  594. FSCK_MSG_GITMODULES_SYMLINK,
  595. ".gitmodules is a symbolic link");
  596. }
  597. if ((backslash = strchr(name, '\\'))) {
  598. while (backslash) {
  599. backslash++;
  600. has_dotgit |= is_ntfs_dotgit(backslash);
  601. if (is_ntfs_dotgitmodules(backslash)) {
  602. if (!S_ISLNK(mode))
  603. oidset_insert(&gitmodules_found, oid);
  604. else
  605. retval += report(options, oid, OBJ_TREE,
  606. FSCK_MSG_GITMODULES_SYMLINK,
  607. ".gitmodules is a symbolic link");
  608. }
  609. backslash = strchr(backslash, '\\');
  610. }
  611. }
  612. if (update_tree_entry_gently(&desc)) {
  613. retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
  614. break;
  615. }
  616. switch (mode) {
  617. /*
  618. * Standard modes..
  619. */
  620. case S_IFREG | 0755:
  621. case S_IFREG | 0644:
  622. case S_IFLNK:
  623. case S_IFDIR:
  624. case S_IFGITLINK:
  625. break;
  626. /*
  627. * This is nonstandard, but we had a few of these
  628. * early on when we honored the full set of mode
  629. * bits..
  630. */
  631. case S_IFREG | 0664:
  632. if (!options->strict)
  633. break;
  634. /* fallthrough */
  635. default:
  636. has_bad_modes = 1;
  637. }
  638. if (o_name) {
  639. switch (verify_ordered(o_mode, o_name, mode, name,
  640. &df_dup_candidates)) {
  641. case TREE_UNORDERED:
  642. not_properly_sorted = 1;
  643. break;
  644. case TREE_HAS_DUPS:
  645. has_dup_entries = 1;
  646. break;
  647. default:
  648. break;
  649. }
  650. }
  651. o_mode = mode;
  652. o_name = name;
  653. }
  654. name_stack_clear(&df_dup_candidates);
  655. if (has_null_sha1)
  656. retval += report(options, oid, OBJ_TREE, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
  657. if (has_full_path)
  658. retval += report(options, oid, OBJ_TREE, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
  659. if (has_empty_name)
  660. retval += report(options, oid, OBJ_TREE, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
  661. if (has_dot)
  662. retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOT, "contains '.'");
  663. if (has_dotdot)
  664. retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTDOT, "contains '..'");
  665. if (has_dotgit)
  666. retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
  667. if (has_zero_pad)
  668. retval += report(options, oid, OBJ_TREE, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
  669. if (has_bad_modes)
  670. retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
  671. if (has_dup_entries)
  672. retval += report(options, oid, OBJ_TREE, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
  673. if (not_properly_sorted)
  674. retval += report(options, oid, OBJ_TREE, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
  675. return retval;
  676. }
  677. static int verify_headers(const void *data, unsigned long size,
  678. const struct object_id *oid, enum object_type type,
  679. struct fsck_options *options)
  680. {
  681. const char *buffer = (const char *)data;
  682. unsigned long i;
  683. for (i = 0; i < size; i++) {
  684. switch (buffer[i]) {
  685. case '\0':
  686. return report(options, oid, type,
  687. FSCK_MSG_NUL_IN_HEADER,
  688. "unterminated header: NUL at offset %ld", i);
  689. case '\n':
  690. if (i + 1 < size && buffer[i + 1] == '\n')
  691. return 0;
  692. }
  693. }
  694. /*
  695. * We did not find double-LF that separates the header
  696. * and the body. Not having a body is not a crime but
  697. * we do want to see the terminating LF for the last header
  698. * line.
  699. */
  700. if (size && buffer[size - 1] == '\n')
  701. return 0;
  702. return report(options, oid, type,
  703. FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
  704. }
  705. static int fsck_ident(const char **ident,
  706. const struct object_id *oid, enum object_type type,
  707. struct fsck_options *options)
  708. {
  709. const char *p = *ident;
  710. char *end;
  711. *ident = strchrnul(*ident, '\n');
  712. if (**ident == '\n')
  713. (*ident)++;
  714. if (*p == '<')
  715. return report(options, oid, type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
  716. p += strcspn(p, "<>\n");
  717. if (*p == '>')
  718. return report(options, oid, type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
  719. if (*p != '<')
  720. return report(options, oid, type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
  721. if (p[-1] != ' ')
  722. return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
  723. p++;
  724. p += strcspn(p, "<>\n");
  725. if (*p != '>')
  726. return report(options, oid, type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
  727. p++;
  728. if (*p != ' ')
  729. return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
  730. p++;
  731. if (*p == '0' && p[1] != ' ')
  732. return report(options, oid, type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
  733. if (date_overflows(parse_timestamp(p, &end, 10)))
  734. return report(options, oid, type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
  735. if ((end == p || *end != ' '))
  736. return report(options, oid, type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
  737. p = end + 1;
  738. if ((*p != '+' && *p != '-') ||
  739. !isdigit(p[1]) ||
  740. !isdigit(p[2]) ||
  741. !isdigit(p[3]) ||
  742. !isdigit(p[4]) ||
  743. (p[5] != '\n'))
  744. return report(options, oid, type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
  745. p += 6;
  746. return 0;
  747. }
  748. static int fsck_commit(const struct object_id *oid,
  749. const char *buffer, unsigned long size,
  750. struct fsck_options *options)
  751. {
  752. struct object_id tree_oid, parent_oid;
  753. unsigned author_count;
  754. int err;
  755. const char *buffer_begin = buffer;
  756. const char *p;
  757. if (verify_headers(buffer, size, oid, OBJ_COMMIT, options))
  758. return -1;
  759. if (!skip_prefix(buffer, "tree ", &buffer))
  760. return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
  761. if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') {
  762. err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
  763. if (err)
  764. return err;
  765. }
  766. buffer = p + 1;
  767. while (skip_prefix(buffer, "parent ", &buffer)) {
  768. if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') {
  769. err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
  770. if (err)
  771. return err;
  772. }
  773. buffer = p + 1;
  774. }
  775. author_count = 0;
  776. while (skip_prefix(buffer, "author ", &buffer)) {
  777. author_count++;
  778. err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
  779. if (err)
  780. return err;
  781. }
  782. if (author_count < 1)
  783. err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
  784. else if (author_count > 1)
  785. err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
  786. if (err)
  787. return err;
  788. if (!skip_prefix(buffer, "committer ", &buffer))
  789. return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
  790. err = fsck_ident(&buffer, oid, OBJ_COMMIT, options);
  791. if (err)
  792. return err;
  793. if (memchr(buffer_begin, '\0', size)) {
  794. err = report(options, oid, OBJ_COMMIT, FSCK_MSG_NUL_IN_COMMIT,
  795. "NUL byte in the commit object body");
  796. if (err)
  797. return err;
  798. }
  799. return 0;
  800. }
  801. static int fsck_tag(const struct object_id *oid, const char *buffer,
  802. unsigned long size, struct fsck_options *options)
  803. {
  804. struct object_id tagged_oid;
  805. int ret = 0;
  806. char *eol;
  807. struct strbuf sb = STRBUF_INIT;
  808. const char *p;
  809. ret = verify_headers(buffer, size, oid, OBJ_TAG, options);
  810. if (ret)
  811. goto done;
  812. if (!skip_prefix(buffer, "object ", &buffer)) {
  813. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
  814. goto done;
  815. }
  816. if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') {
  817. ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
  818. if (ret)
  819. goto done;
  820. }
  821. buffer = p + 1;
  822. if (!skip_prefix(buffer, "type ", &buffer)) {
  823. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
  824. goto done;
  825. }
  826. eol = strchr(buffer, '\n');
  827. if (!eol) {
  828. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
  829. goto done;
  830. }
  831. if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
  832. ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
  833. if (ret)
  834. goto done;
  835. buffer = eol + 1;
  836. if (!skip_prefix(buffer, "tag ", &buffer)) {
  837. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
  838. goto done;
  839. }
  840. eol = strchr(buffer, '\n');
  841. if (!eol) {
  842. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
  843. goto done;
  844. }
  845. strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
  846. if (check_refname_format(sb.buf, 0)) {
  847. ret = report(options, oid, OBJ_TAG,
  848. FSCK_MSG_BAD_TAG_NAME,
  849. "invalid 'tag' name: %.*s",
  850. (int)(eol - buffer), buffer);
  851. if (ret)
  852. goto done;
  853. }
  854. buffer = eol + 1;
  855. if (!skip_prefix(buffer, "tagger ", &buffer)) {
  856. /* early tags do not contain 'tagger' lines; warn only */
  857. ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
  858. if (ret)
  859. goto done;
  860. }
  861. else
  862. ret = fsck_ident(&buffer, oid, OBJ_TAG, options);
  863. done:
  864. strbuf_release(&sb);
  865. return ret;
  866. }
  867. /*
  868. * Like builtin/submodule--helper.c's starts_with_dot_slash, but without
  869. * relying on the platform-dependent is_dir_sep helper.
  870. *
  871. * This is for use in checking whether a submodule URL is interpreted as
  872. * relative to the current directory on any platform, since \ is a
  873. * directory separator on Windows but not on other platforms.
  874. */
  875. static int starts_with_dot_slash(const char *str)
  876. {
  877. return str[0] == '.' && (str[1] == '/' || str[1] == '\\');
  878. }
  879. /*
  880. * Like starts_with_dot_slash, this is a variant of submodule--helper's
  881. * helper of the same name with the twist that it accepts backslash as a
  882. * directory separator even on non-Windows platforms.
  883. */
  884. static int starts_with_dot_dot_slash(const char *str)
  885. {
  886. return str[0] == '.' && starts_with_dot_slash(str + 1);
  887. }
  888. static int submodule_url_is_relative(const char *url)
  889. {
  890. return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);
  891. }
  892. /*
  893. * Count directory components that a relative submodule URL should chop
  894. * from the remote_url it is to be resolved against.
  895. *
  896. * In other words, this counts "../" components at the start of a
  897. * submodule URL.
  898. *
  899. * Returns the number of directory components to chop and writes a
  900. * pointer to the next character of url after all leading "./" and
  901. * "../" components to out.
  902. */
  903. static int count_leading_dotdots(const char *url, const char **out)
  904. {
  905. int result = 0;
  906. while (1) {
  907. if (starts_with_dot_dot_slash(url)) {
  908. result++;
  909. url += strlen("../");
  910. continue;
  911. }
  912. if (starts_with_dot_slash(url)) {
  913. url += strlen("./");
  914. continue;
  915. }
  916. *out = url;
  917. return result;
  918. }
  919. }
  920. /*
  921. * Check whether a transport is implemented by git-remote-curl.
  922. *
  923. * If it is, returns 1 and writes the URL that would be passed to
  924. * git-remote-curl to the "out" parameter.
  925. *
  926. * Otherwise, returns 0 and leaves "out" untouched.
  927. *
  928. * Examples:
  929. * http::https://example.com/repo.git -> 1, https://example.com/repo.git
  930. * https://example.com/repo.git -> 1, https://example.com/repo.git
  931. * git://example.com/repo.git -> 0
  932. *
  933. * This is for use in checking for previously exploitable bugs that
  934. * required a submodule URL to be passed to git-remote-curl.
  935. */
  936. static int url_to_curl_url(const char *url, const char **out)
  937. {
  938. /*
  939. * We don't need to check for case-aliases, "http.exe", and so
  940. * on because in the default configuration, is_transport_allowed
  941. * prevents URLs with those schemes from being cloned
  942. * automatically.
  943. */
  944. if (skip_prefix(url, "http::", out) ||
  945. skip_prefix(url, "https::", out) ||
  946. skip_prefix(url, "ftp::", out) ||
  947. skip_prefix(url, "ftps::", out))
  948. return 1;
  949. if (starts_with(url, "http://") ||
  950. starts_with(url, "https://") ||
  951. starts_with(url, "ftp://") ||
  952. starts_with(url, "ftps://")) {
  953. *out = url;
  954. return 1;
  955. }
  956. return 0;
  957. }
  958. static int check_submodule_url(const char *url)
  959. {
  960. const char *curl_url;
  961. if (looks_like_command_line_option(url))
  962. return -1;
  963. if (submodule_url_is_relative(url)) {
  964. char *decoded;
  965. const char *next;
  966. int has_nl;
  967. /*
  968. * This could be appended to an http URL and url-decoded;
  969. * check for malicious characters.
  970. */
  971. decoded = url_decode(url);
  972. has_nl = !!strchr(decoded, '\n');
  973. free(decoded);
  974. if (has_nl)
  975. return -1;
  976. /*
  977. * URLs which escape their root via "../" can overwrite
  978. * the host field and previous components, resolving to
  979. * URLs like https::example.com/submodule.git and
  980. * https:///example.com/submodule.git that were
  981. * susceptible to CVE-2020-11008.
  982. */
  983. if (count_leading_dotdots(url, &next) > 0 &&
  984. (*next == ':' || *next == '/'))
  985. return -1;
  986. }
  987. else if (url_to_curl_url(url, &curl_url)) {
  988. struct credential c = CREDENTIAL_INIT;
  989. int ret = 0;
  990. if (credential_from_url_gently(&c, curl_url, 1) ||
  991. !*c.host)
  992. ret = -1;
  993. credential_clear(&c);
  994. return ret;
  995. }
  996. return 0;
  997. }
  998. struct fsck_gitmodules_data {
  999. const struct object_id *oid;
  1000. struct fsck_options *options;
  1001. int ret;
  1002. };
  1003. static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
  1004. {
  1005. struct fsck_gitmodules_data *data = vdata;
  1006. const char *subsection, *key;
  1007. size_t subsection_len;
  1008. char *name;
  1009. if (parse_config_key(var, "submodule", &subsection, &subsection_len, &key) < 0 ||
  1010. !subsection)
  1011. return 0;
  1012. name = xmemdupz(subsection, subsection_len);
  1013. if (check_submodule_name(name) < 0)
  1014. data->ret |= report(data->options,
  1015. data->oid, OBJ_BLOB,
  1016. FSCK_MSG_GITMODULES_NAME,
  1017. "disallowed submodule name: %s",
  1018. name);
  1019. if (!strcmp(key, "url") && value &&
  1020. check_submodule_url(value) < 0)
  1021. data->ret |= report(data->options,
  1022. data->oid, OBJ_BLOB,
  1023. FSCK_MSG_GITMODULES_URL,
  1024. "disallowed submodule url: %s",
  1025. value);
  1026. if (!strcmp(key, "path") && value &&
  1027. looks_like_command_line_option(value))
  1028. data->ret |= report(data->options,
  1029. data->oid, OBJ_BLOB,
  1030. FSCK_MSG_GITMODULES_PATH,
  1031. "disallowed submodule path: %s",
  1032. value);
  1033. if (!strcmp(key, "update") && value &&
  1034. parse_submodule_update_type(value) == SM_UPDATE_COMMAND)
  1035. data->ret |= report(data->options, data->oid, OBJ_BLOB,
  1036. FSCK_MSG_GITMODULES_UPDATE,
  1037. "disallowed submodule update setting: %s",
  1038. value);
  1039. free(name);
  1040. return 0;
  1041. }
  1042. static int fsck_blob(const struct object_id *oid, const char *buf,
  1043. unsigned long size, struct fsck_options *options)
  1044. {
  1045. struct fsck_gitmodules_data data;
  1046. struct config_options config_opts = { 0 };
  1047. if (!oidset_contains(&gitmodules_found, oid))
  1048. return 0;
  1049. oidset_insert(&gitmodules_done, oid);
  1050. if (object_on_skiplist(options, oid))
  1051. return 0;
  1052. if (!buf) {
  1053. /*
  1054. * A missing buffer here is a sign that the caller found the
  1055. * blob too gigantic to load into memory. Let's just consider
  1056. * that an error.
  1057. */
  1058. return report(options, oid, OBJ_BLOB,
  1059. FSCK_MSG_GITMODULES_LARGE,
  1060. ".gitmodules too large to parse");
  1061. }
  1062. data.oid = oid;
  1063. data.options = options;
  1064. data.ret = 0;
  1065. config_opts.error_action = CONFIG_ERROR_SILENT;
  1066. if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
  1067. ".gitmodules", buf, size, &data, &config_opts))
  1068. data.ret |= report(options, oid, OBJ_BLOB,
  1069. FSCK_MSG_GITMODULES_PARSE,
  1070. "could not parse gitmodules blob");
  1071. return data.ret;
  1072. }
  1073. int fsck_object(struct object *obj, void *data, unsigned long size,
  1074. struct fsck_options *options)
  1075. {
  1076. if (!obj)
  1077. return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
  1078. if (obj->type == OBJ_BLOB)
  1079. return fsck_blob(&obj->oid, data, size, options);
  1080. if (obj->type == OBJ_TREE)
  1081. return fsck_tree(&obj->oid, data, size, options);
  1082. if (obj->type == OBJ_COMMIT)
  1083. return fsck_commit(&obj->oid, data, size, options);
  1084. if (obj->type == OBJ_TAG)
  1085. return fsck_tag(&obj->oid, data, size, options);
  1086. return report(options, &obj->oid, obj->type,
  1087. FSCK_MSG_UNKNOWN_TYPE,
  1088. "unknown type '%d' (internal fsck error)",
  1089. obj->type);
  1090. }
  1091. int fsck_error_function(struct fsck_options *o,
  1092. const struct object_id *oid,
  1093. enum object_type object_type,
  1094. int msg_type, const char *message)
  1095. {
  1096. if (msg_type == FSCK_WARN) {
  1097. warning("object %s: %s", fsck_describe_object(o, oid), message);
  1098. return 0;
  1099. }
  1100. error("object %s: %s", fsck_describe_object(o, oid), message);
  1101. return 1;
  1102. }
  1103. int fsck_finish(struct fsck_options *options)
  1104. {
  1105. int ret = 0;
  1106. struct oidset_iter iter;
  1107. const struct object_id *oid;
  1108. oidset_iter_init(&gitmodules_found, &iter);
  1109. while ((oid = oidset_iter_next(&iter))) {
  1110. enum object_type type;
  1111. unsigned long size;
  1112. char *buf;
  1113. if (oidset_contains(&gitmodules_done, oid))
  1114. continue;
  1115. buf = read_object_file(oid, &type, &size);
  1116. if (!buf) {
  1117. if (is_promisor_object(oid))
  1118. continue;
  1119. ret |= report(options,
  1120. oid, OBJ_BLOB,
  1121. FSCK_MSG_GITMODULES_MISSING,
  1122. "unable to read .gitmodules blob");
  1123. continue;
  1124. }
  1125. if (type == OBJ_BLOB)
  1126. ret |= fsck_blob(oid, buf, size, options);
  1127. else
  1128. ret |= report(options,
  1129. oid, type,
  1130. FSCK_MSG_GITMODULES_BLOB,
  1131. "non-blob found at .gitmodules");
  1132. free(buf);
  1133. }
  1134. oidset_clear(&gitmodules_found);
  1135. oidset_clear(&gitmodules_done);
  1136. return ret;
  1137. }