Revert "deal with too small/long requests"

This reverts commit efa1f639fc.
This commit is contained in:
Solene Rapenne 2021-03-01 19:35:41 +01:00
parent 9525d66afb
commit e3b5fb2ab3
1 changed files with 6 additions and 15 deletions

21
main.c
View File

@ -20,7 +20,7 @@
#include "utils.h" #include "utils.h"
#define GEMINI_PART 9 #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); drop_privileges(user, chroot_dir);
size_t reqlen = 0;
/* /*
* read 1024 chars from stdin * read 1024 chars from stdin
* to get the request * to get the request
*/ */
reqlen = fread(request, 1, GEMINI_REQUEST_MAX, stdin); if (fgets(request, GEMINI_REQUEST_MAX, stdin) == NULL) {
status(59, "request is too long (1024 max)");
/* now should end of file, or request is too long */ errlog("request is too long (1024 max): %s", request);
if (feof(stdin) == 0) {
status(59, "request too long");
errlog("request too long");
} }
/* remove \r\n at the end of string */ /* remove \r\n at the end of string */
pos = strstr(request, "\r\n"); pos = strchr(request, '\r');
if (pos != NULL) { if (pos != NULL)
*pos = '\0'; *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 * 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) { if (strncmp(request, "gemini://", GEMINI_PART) != 0) {
/* error code url malformed */ /* error code url malformed */
status(59, "request malformed : must start with gemini://");
errlog("request «%s» doesn't match gemini://", errlog("request «%s» doesn't match gemini://",
request); request);
} }