summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-04-30 09:27:33 +0200
committerdefault <nobody@localhost>2024-04-30 09:27:33 +0200
commit4e23570c215aaa2bc2611056b57d90e41621a001 (patch)
tree2eaf27d4b87ea0313d55437cb1eaef870dbd6ce0 /data.c
parent96830967e15bd6b1a89686c8c729b096ae6c4550 (diff)
Added more internal integrity checks.
index_add_md5() barfs if the md5 is not valid.
Diffstat (limited to 'data.c')
-rw-r--r--data.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/data.c b/data.c
index 0d8aa8b..82d0acc 100644
--- a/data.c
+++ b/data.c
@@ -340,6 +340,12 @@ double f_ctime(const char *fn)
}
+int is_md5_hex(const char *md5)
+{
+ return xs_is_hex(md5) && strlen(md5) == 32;
+}
+
+
/** database 2.1+ **/
/** indexes **/
@@ -351,6 +357,11 @@ int index_add_md5(const char *fn, const char *md5)
int status = 201; /* Created */
FILE *f;
+ if (!is_md5_hex(md5)) {
+ srv_log(xs_fmt("index_add_md5: bad md5 %s %s", fn, md5));
+ return 400;
+ }
+
pthread_mutex_lock(&data_mutex);
if ((f = fopen(fn, "a")) != NULL) {
@@ -606,7 +617,7 @@ static xs_str *_object_fn_by_md5(const char *md5, const char *func)
if (md5[0] == '-')
ok = 0;
else
- if (!xs_is_hex(md5) || strlen(md5) != 32) {
+ if (!is_md5_hex(md5)) {
srv_log(xs_fmt("_object_fn_by_md5() [from %s()]: bad md5 '%s'", func, md5));
ok = 0;
}