Discard avatar uploads that are not images.

This commit is contained in:
default 2023-08-14 15:12:09 +02:00
parent 2696f62dc5
commit 16c14060a8

12
html.c
View File

@ -2415,11 +2415,14 @@ int html_post_handler(const xs_dict *req, const char *q_path,
/* avatar upload */
xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file");
if (!xs_is_null(avatar_file) && xs_type(avatar_file) == XSTYPE_LIST) {
char *fn = xs_list_get(avatar_file, 0);
if (xs_type(avatar_file) == XSTYPE_LIST) {
const char *fn = xs_list_get(avatar_file, 0);
if (*fn != '\0') {
char *ext = strrchr(fn, '.');
if (fn && *fn) {
const char *mimetype = xs_mime_by_ext(fn);
if (xs_startswith(mimetype, "image/")) {
const char *ext = strrchr(fn, '.');
xs *id = xs_fmt("avatar%s", ext);
xs *url = xs_fmt("%s/s/%s", snac.actor, id);
int fo = xs_number_get(xs_list_get(avatar_file, 1));
@ -2431,6 +2434,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
snac.config = xs_dict_set(snac.config, "avatar", url);
}
}
}
/* password change? */
if ((p1 = xs_dict_get(p_vars, "passwd1")) != NULL &&