|
24 | 24 | #include "credential.h" |
25 | 25 | #include "help.h" |
26 | 26 |
|
| 27 | +static ssize_t max_tree_entry_len = 4096; |
| 28 | + |
27 | 29 | #define STR(x) #x |
28 | 30 | #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, |
29 | 31 | static struct { |
@@ -154,15 +156,29 @@ void fsck_set_msg_type(struct fsck_options *options, |
154 | 156 | const char *msg_id_str, const char *msg_type_str) |
155 | 157 | { |
156 | 158 | int msg_id = parse_msg_id(msg_id_str); |
157 | | - enum fsck_msg_type msg_type = parse_msg_type(msg_type_str); |
| 159 | + char *to_free = NULL; |
| 160 | + enum fsck_msg_type msg_type; |
158 | 161 |
|
159 | 162 | if (msg_id < 0) |
160 | 163 | die("Unhandled message id: %s", msg_id_str); |
161 | 164 |
|
| 165 | + if (msg_id == FSCK_MSG_LARGE_PATHNAME) { |
| 166 | + const char *colon = strchr(msg_type_str, ':'); |
| 167 | + if (colon) { |
| 168 | + msg_type_str = to_free = |
| 169 | + xmemdupz(msg_type_str, colon - msg_type_str); |
| 170 | + colon++; |
| 171 | + if (!git_parse_ssize_t(colon, &max_tree_entry_len)) |
| 172 | + die("unable to parse max tree entry len: %s", colon); |
| 173 | + } |
| 174 | + } |
| 175 | + msg_type = parse_msg_type(msg_type_str); |
| 176 | + |
162 | 177 | if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL) |
163 | 178 | die("Cannot demote %s to %s", msg_id_str, msg_type_str); |
164 | 179 |
|
165 | 180 | fsck_set_msg_type_from_ids(options, msg_id, msg_type); |
| 181 | + free(to_free); |
166 | 182 | } |
167 | 183 |
|
168 | 184 | void fsck_set_msg_types(struct fsck_options *options, const char *values) |
@@ -578,6 +594,7 @@ static int fsck_tree(const struct object_id *tree_oid, |
578 | 594 | int has_bad_modes = 0; |
579 | 595 | int has_dup_entries = 0; |
580 | 596 | int not_properly_sorted = 0; |
| 597 | + int has_large_name = 0; |
581 | 598 | struct tree_desc desc; |
582 | 599 | unsigned o_mode; |
583 | 600 | const char *o_name; |
@@ -607,6 +624,7 @@ static int fsck_tree(const struct object_id *tree_oid, |
607 | 624 | has_dotdot |= !strcmp(name, ".."); |
608 | 625 | has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name); |
609 | 626 | has_zero_pad |= *(char *)desc.buffer == '0'; |
| 627 | + has_large_name |= tree_entry_len(&desc.entry) > max_tree_entry_len; |
610 | 628 |
|
611 | 629 | if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) { |
612 | 630 | if (!S_ISLNK(mode)) |
@@ -749,6 +767,10 @@ static int fsck_tree(const struct object_id *tree_oid, |
749 | 767 | retval += report(options, tree_oid, OBJ_TREE, |
750 | 768 | FSCK_MSG_TREE_NOT_SORTED, |
751 | 769 | "not properly sorted"); |
| 770 | + if (has_large_name) |
| 771 | + retval += report(options, tree_oid, OBJ_TREE, |
| 772 | + FSCK_MSG_LARGE_PATHNAME, |
| 773 | + "contains excessively large pathname"); |
752 | 774 | return retval; |
753 | 775 | } |
754 | 776 |
|
|
0 commit comments