MCPcopy Create free account
hub / github.com/git/git / verify_headers

Function verify_headers

fsck.c:829–859  ·  view source on GitHub ↗

* Confirm that the headers of a commit or tag object end in a reasonable way, * either with the usual "\n\n" separator, or at least with a trailing newline * on the final header line. * * This property is important for the memory safety of our callers. It allows * them to scan the buffer linewise without constantly checking the remaining * size as long as: * * - they check that there are

Source from the content-addressed store, hash-verified

827 * OK for them to use helpers like parse_oid_hex(), or even skip_prefix().
828 */
829static int verify_headers(const void *data, unsigned long size,
830 const struct object_id *oid, enum object_type type,
831 struct fsck_options *options)
832{
833 const char *buffer = (const char *)data;
834 unsigned long i;
835
836 for (i = 0; i < size; i++) {
837 switch (buffer[i]) {
838 case '\0':
839 return report(options, oid, type,
840 FSCK_MSG_NUL_IN_HEADER,
841 "unterminated header: NUL at offset %ld", i);
842 case '\n':
843 if (i + 1 < size && buffer[i + 1] == '\n')
844 return 0;
845 }
846 }
847
848 /*
849 * We did not find double-LF that separates the header
850 * and the body. Not having a body is not a crime but
851 * we do want to see the terminating LF for the last header
852 * line.
853 */
854 if (size && buffer[size - 1] == '\n')
855 return 0;
856
857 return report(options, oid, type,
858 FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
859}
860
861static timestamp_t parse_timestamp_from_buf(const char **start, const char *end)
862{

Callers 2

fsck_commitFunction · 0.85
fsck_tag_standaloneFunction · 0.85

Calls 1

reportFunction · 0.70

Tested by

no test coverage detected