ensure errors msg are followed by \n, specify in a define the number of matches we need, remove bad structure init
This commit is contained in:
parent
be0f86df8d
commit
5063f3e95b
22
vger.c
22
vger.c
|
@ -43,6 +43,7 @@ stop(const int r, const char *fmt, ...)
|
|||
va_start(ap2, fmt);
|
||||
vfprintf(stderr, fmt, ap2);
|
||||
va_end(ap2);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
exit(r);
|
||||
|
@ -344,8 +345,8 @@ check_request(char *request)
|
|||
*/
|
||||
char *pos = NULL;
|
||||
|
||||
|
||||
/* read 1024 +1 chars from stdin to get the request (1024 + \0) */
|
||||
|
||||
if (fgets(request, GEMINI_REQUEST_MAX, stdin) == NULL) {
|
||||
/* EOF reached before reading anything */
|
||||
if (feof(stdin)) {
|
||||
|
@ -368,22 +369,9 @@ check_request(char *request)
|
|||
/* remove \r\n at the end of string */
|
||||
request[strcspn(request, "\r\n")] = '\0';
|
||||
|
||||
/*
|
||||
* check if the beginning of the request starts with
|
||||
* gemini://
|
||||
*/
|
||||
if (strncmp(request, "gemini://", GEMINI_PART) != 0) {
|
||||
/* error code url malformed */
|
||||
status(59, "request «%s» doesn't match gemini://", request);
|
||||
stop(EXIT_FAILURE, "request «%s» doesn't match gemini://", request);
|
||||
}
|
||||
|
||||
/* save request for logs */
|
||||
estrlcpy(_request, request, sizeof(_request));
|
||||
|
||||
/* remove the gemini:// part */
|
||||
memmove(request, request + GEMINI_PART, strlen(request) + 1 - GEMINI_PART);
|
||||
|
||||
/* remove all "/.." for safety reasons */
|
||||
while ((pos = strstr(request, "/..")) != NULL)
|
||||
memmove(request, pos + 3, strlen(pos) + 1 - 3); /* "/.." = 3 */
|
||||
|
@ -508,11 +496,11 @@ get_query(char *path, char *query, size_t querysiz)
|
|||
void
|
||||
split_request(const char *request, char *hostname, char *path, char *query)
|
||||
{
|
||||
regex_t greg = {0}; /* compiled gemini regex */
|
||||
regmatch_t *match = {0}; /* matches founds */
|
||||
size_t nmatch = 4; /* number of substrings to look for */
|
||||
size_t nmatch = SE_MAX; /* 3 "()" + 1 for whole match */
|
||||
char buf[BUFSIZ] = {'\0'}; /* to handle error messages */
|
||||
int ret = 0;
|
||||
regex_t greg; /* compiled gemini regex */
|
||||
regmatch_t match[SE_MAX]; /* matches founds */
|
||||
|
||||
ret = regcomp(&greg, _gemini_regex, REG_EXTENDED);
|
||||
if (ret != 0) {
|
||||
|
|
Loading…
Reference in New Issue