From e3b5fb2ab3c93c4886b73594b3b69cc70d91edd7 Mon Sep 17 00:00:00 2001 From: Solene Rapenne Date: Mon, 1 Mar 2021 19:35:41 +0100 Subject: [PATCH] Revert "deal with too small/long requests" This reverts commit efa1f639fccb7c5048df4305d96e8c2a46eacd24. --- main.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index e3c4bb2..7c8682b 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,7 @@ #include "utils.h" #define GEMINI_PART 9 -#define GEMINI_REQUEST_MAX 1024 /* https://gemini.circumlunar.space/docs/specification.html */ +#define GEMINI_REQUEST_MAX 1024 /* see https://gemini.circumlunar.space/docs/specification.html */ @@ -358,27 +358,19 @@ main(int argc, char **argv) */ drop_privileges(user, chroot_dir); - size_t reqlen = 0; /* * read 1024 chars from stdin * to get the request */ - reqlen = fread(request, 1, GEMINI_REQUEST_MAX, stdin); - - /* now should end of file, or request is too long */ - if (feof(stdin) == 0) { - status(59, "request too long"); - errlog("request too long"); + if (fgets(request, GEMINI_REQUEST_MAX, stdin) == NULL) { + status(59, "request is too long (1024 max)"); + errlog("request is too long (1024 max): %s", request); } /* remove \r\n at the end of string */ - pos = strstr(request, "\r\n"); - if (pos != NULL) { + pos = strchr(request, '\r'); + if (pos != NULL) *pos = '\0'; - } else { - status(59, "malformed request, must end with \r\n"); - errlog("malformed request, must end with \r\n"); - } /* * check if the beginning of the request starts with @@ -386,7 +378,6 @@ main(int argc, char **argv) */ if (strncmp(request, "gemini://", GEMINI_PART) != 0) { /* error code url malformed */ - status(59, "request malformed : must start with gemini://"); errlog("request «%s» doesn't match gemini://", request); }