commit 4e23570
default
·
2024-04-30 07:27:33 +0000 UTC
parent 9683096
Added more internal integrity checks. index_add_md5() barfs if the md5 is not valid.
1 files changed,
+12,
-1
M
data.c
M
data.c
+12,
-1
1@@ -340,6 +340,12 @@ double f_ctime(const char *fn)
2 }
3
4
5+int is_md5_hex(const char *md5)
6+{
7+ return xs_is_hex(md5) && strlen(md5) == 32;
8+}
9+
10+
11 /** database 2.1+ **/
12
13 /** indexes **/
14@@ -351,6 +357,11 @@ int index_add_md5(const char *fn, const char *md5)
15 int status = 201; /* Created */
16 FILE *f;
17
18+ if (!is_md5_hex(md5)) {
19+ srv_log(xs_fmt("index_add_md5: bad md5 %s %s", fn, md5));
20+ return 400;
21+ }
22+
23 pthread_mutex_lock(&data_mutex);
24
25 if ((f = fopen(fn, "a")) != NULL) {
26@@ -606,7 +617,7 @@ static xs_str *_object_fn_by_md5(const char *md5, const char *func)
27 if (md5[0] == '-')
28 ok = 0;
29 else
30- if (!xs_is_hex(md5) || strlen(md5) != 32) {
31+ if (!is_md5_hex(md5)) {
32 srv_log(xs_fmt("_object_fn_by_md5() [from %s()]: bad md5 '%s'", func, md5));
33 ok = 0;
34 }