|
12 | 12 | #include "decorate.h"
|
13 | 13 | #include "oidset.h"
|
14 | 14 | #include "packfile.h"
|
| 15 | +#include "submodule-config.h" |
| 16 | +#include "config.h" |
15 | 17 |
|
16 | 18 | static struct oidset gitmodules_found = OIDSET_INIT;
|
17 | 19 | static struct oidset gitmodules_done = OIDSET_INIT;
|
@@ -59,6 +61,8 @@ static struct oidset gitmodules_done = OIDSET_INIT;
|
59 | 61 | FUNC(ZERO_PADDED_DATE, ERROR) \
|
60 | 62 | FUNC(GITMODULES_MISSING, ERROR) \
|
61 | 63 | FUNC(GITMODULES_BLOB, ERROR) \
|
| 64 | + FUNC(GITMODULES_PARSE, ERROR) \ |
| 65 | + FUNC(GITMODULES_NAME, ERROR) \ |
62 | 66 | /* warnings */ \
|
63 | 67 | FUNC(BAD_FILEMODE, WARN) \
|
64 | 68 | FUNC(EMPTY_NAME, WARN) \
|
@@ -911,10 +915,64 @@ static int fsck_tag(struct tag *tag, const char *data,
|
911 | 915 | return fsck_tag_buffer(tag, data, size, options);
|
912 | 916 | }
|
913 | 917 |
|
| 918 | +struct fsck_gitmodules_data { |
| 919 | + struct object *obj; |
| 920 | + struct fsck_options *options; |
| 921 | + int ret; |
| 922 | +}; |
| 923 | + |
| 924 | +static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) |
| 925 | +{ |
| 926 | + struct fsck_gitmodules_data *data = vdata; |
| 927 | + const char *subsection, *key; |
| 928 | + int subsection_len; |
| 929 | + char *name; |
| 930 | + |
| 931 | + if (parse_config_key(var, "submodule", &subsection, &subsection_len, &key) < 0 || |
| 932 | + !subsection) |
| 933 | + return 0; |
| 934 | + |
| 935 | + name = xmemdupz(subsection, subsection_len); |
| 936 | + if (check_submodule_name(name) < 0) |
| 937 | + data->ret |= report(data->options, data->obj, |
| 938 | + FSCK_MSG_GITMODULES_NAME, |
| 939 | + "disallowed submodule name: %s", |
| 940 | + name); |
| 941 | + free(name); |
| 942 | + |
| 943 | + return 0; |
| 944 | +} |
| 945 | + |
914 | 946 | static int fsck_blob(struct blob *blob, const char *buf,
|
915 | 947 | unsigned long size, struct fsck_options *options)
|
916 | 948 | {
|
917 |
| - return 0; |
| 949 | + struct fsck_gitmodules_data data; |
| 950 | + |
| 951 | + if (!oidset_contains(&gitmodules_found, &blob->object.oid)) |
| 952 | + return 0; |
| 953 | + oidset_insert(&gitmodules_done, &blob->object.oid); |
| 954 | + |
| 955 | + if (!buf) { |
| 956 | + /* |
| 957 | + * A missing buffer here is a sign that the caller found the |
| 958 | + * blob too gigantic to load into memory. Let's just consider |
| 959 | + * that an error. |
| 960 | + */ |
| 961 | + return report(options, &blob->object, |
| 962 | + FSCK_MSG_GITMODULES_PARSE, |
| 963 | + ".gitmodules too large to parse"); |
| 964 | + } |
| 965 | + |
| 966 | + data.obj = &blob->object; |
| 967 | + data.options = options; |
| 968 | + data.ret = 0; |
| 969 | + if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB, |
| 970 | + ".gitmodules", buf, size, &data)) |
| 971 | + data.ret |= report(options, &blob->object, |
| 972 | + FSCK_MSG_GITMODULES_PARSE, |
| 973 | + "could not parse gitmodules blob"); |
| 974 | + |
| 975 | + return data.ret; |
918 | 976 | }
|
919 | 977 |
|
920 | 978 | int fsck_object(struct object *obj, void *data, unsigned long size,
|
|
0 commit comments