diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2025-02-14 12:15:10 +0100 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2025-02-14 12:15:10 +0100 |
commit | a976d39e6b5f3fbc8e8d2286daf6a22b858f7dc8 (patch) | |
tree | c4f3dada5f2924a3798372ee9f95edfc14badc69 | |
parent | f9a16b55db60f2f7c6065c5a94ee7e4aaac3f16b (diff) |
-rw-r--r-- | main.c | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -63,34 +63,48 @@ main(void) enum kcgi_err parse_err; struct kreq r; - if (kutil_openlog(LOG_FILE) == 0) + if (kutil_openlog(LOG_FILE) == 0) { http_exit(NULL, KHTTP_500, "Unable to open %s", LOG_FILE); + return EXIT_SUCCESS; + } parse_err = khttp_parse(&r, NULL, 0, pages, PAGE__MAX, PAGE_BROWSE); - if (parse_err != KCGI_OK) + if (parse_err != KCGI_OK) { http_exit(NULL, KHTTP_500, "Unable to parse request: %s", kcgi_strerror(parse_err)); + return EXIT_SUCCESS; + } data_dir = config_data_dir(); - if (data_dir == NULL) + if (data_dir == NULL) { http_exit(NULL, KHTTP_500, "Data dir not configured"); + goto end; + } /* A bit of security cannot hurt */ if (-1 == unveil(data_dir, "rwc") || -1 == unveil(TEMPLATE_DIR, "r") - || -1 == unveil(NULL, NULL)) + || -1 == unveil(NULL, NULL)) { http_exit(&r, KHTTP_500, "Unveil failed: %s", strerror(errno)); - if (-1 == pledge("stdio rpath wpath cpath", NULL)) + goto end; + } + if (-1 == pledge("stdio rpath wpath cpath", NULL)) { http_exit(&r, KHTTP_500, "Pledge failed: %s", strerror(errno)); + goto end; + } /* * Make sure basic request parameters are as expected : GET or POST, * valid page and HTML document */ - if (r.method != KMETHOD_GET && r.method != KMETHOD_POST) + if (r.method != KMETHOD_GET && r.method != KMETHOD_POST) { http_exit(&r, KHTTP_405, NULL); - if (r.page == PAGE__MAX) + goto end; + } + if (r.page == PAGE__MAX) { http_exit(&r, KHTTP_404, NULL); + goto end; + } switch (r.page) { case PAGE_BROWSE: @@ -109,8 +123,10 @@ main(void) break; default: http_exit(&r, KHTTP_404, NULL); + goto end; } +end: khttp_free(&r); return EXIT_SUCCESS; |