summaryrefslogtreecommitdiff
path: root/browse.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2023-08-29 18:13:30 +0200
committerVincent Douillet <vincent@vdouillet.fr>2023-08-29 18:13:30 +0200
commit2acc8db2762b98eb061241109877527d58a560bc (patch)
tree4f71b3bc0f934b76f839a5ee3640c91b972c1912 /browse.c
parent26a77087027327d72d7229866a1ce12ad11a4d63 (diff)
use PATH_MAX
Diffstat (limited to 'browse.c')
-rw-r--r--browse.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/browse.c b/browse.c
index a129eb6..5093242 100644
--- a/browse.c
+++ b/browse.c
@@ -31,6 +31,7 @@
#include <dirent.h>
#include <kcgi.h>
#include <kcgihtml.h>
+#include <limits.h>
#include <stdbool.h>
#include <string.h>
@@ -60,7 +61,7 @@ browse(struct kreq * r)
DIR *data_dir;
char *file_name;
size_t url_size;
- char url[URL_LENGTH_MAX], current_dir[URL_LENGTH_MAX];
+ char url[PATH_MAX], current_dir[PATH_MAX];
struct khtmlreq html;
/* check that the requested URL can be safely processed */
@@ -68,11 +69,11 @@ browse(struct kreq * r)
http_exit(r, KHTTP_400, "browse: Invalid request path");
/* list requested directory content */
- url_size = url_build(current_dir, URL_LENGTH_MAX, DATA_DIR, r->path,
+ url_size = url_build(current_dir, PATH_MAX, DATA_DIR, r->path,
NULL);
if (url_size == 0)
http_exit(r, KHTTP_404, "browse: Unable to build data path");
- if (url_size >= URL_LENGTH_MAX)
+ if (url_size >= PATH_MAX)
http_exit(r, KHTTP_414, NULL);
data_dir = opendir(current_dir);
if (NULL == data_dir)
@@ -99,8 +100,8 @@ browse(struct kreq * r)
file_name = dir->d_name;
if (strcmp(".", file_name) == 0 || strcmp("..", file_name) == 0)
continue;
- url_size = build_browse_url(r, url, URL_LENGTH_MAX, file_name);
- if (url_size == 0 || url_size >= URL_LENGTH_MAX) {
+ url_size = build_browse_url(r, url, PATH_MAX, file_name);
+ if (url_size == 0 || url_size >= PATH_MAX) {
kutil_warn(r, NULL, "browse: Detected URL overflow: %s", url);
continue;
}