diff options
| author | grunfink <grunfink@noreply.codeberg.org> | 2026-04-05 18:02:45 +0200 |
|---|---|---|
| committer | grunfink <grunfink@noreply.codeberg.org> | 2026-04-05 18:02:45 +0200 |
| commit | cf8f02765a769c27b41efcf479544d41e019036e (patch) | |
| tree | 37c655d56af25f37c5218f2185244acedb94c127 | |
| parent | 42f4c101c13e42c90263c376ae839f8ad87baea4 (diff) | |
| parent | 63903b9c46ad30e5007b689dc68867ae3aa13a5b (diff) | |
Merge pull request 'static files: allow files in a subdirectory' (#541) from lbr/snac2:master into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/541
| -rw-r--r-- | data.c | 15 | ||||
| -rw-r--r-- | html.c | 2 |
2 files changed, 10 insertions, 7 deletions
@@ -2673,14 +2673,17 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size, } else { /* newer or never downloaded; read the full file */ + struct stat sb; FILE *f; - if ((f = fopen(fn, "rb")) != NULL) { - *size = XS_ALL; - *data = xs_read(f, size); - fclose(f); + if (lstat(fn, &sb) == 0 && (sb.st_mode&S_IFMT) == S_IFREG) { + if ((f = fopen(fn, "rb")) != NULL) { + *size = XS_ALL; + *data = xs_read(f, size); + fclose(f); - status = HTTP_STATUS_OK; + status = HTTP_STATUS_OK; + } } } @@ -2699,7 +2702,7 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size, xs_str *_static_fn(snac *snac, const char *id) /* gets the filename for a static file */ { - if (strchr(id, '/')) + if (strstr(id, "..")) return NULL; else return xs_fmt("%s/static/%s", snac->basedir, id); @@ -5073,7 +5073,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, } else if (xs_startswith(p_path, "s/")) { /** a static file **/ - xs *l = xs_split(p_path, "/"); + xs *l = xs_split_n(p_path, "/", 1); const char *id = xs_list_get(l, 1); int sz; |