mirror of https://github.com/omar-polo/gmid.git
trim_req_iri: set error string
This commit is contained in:
parent
72bbed9136
commit
c4f682f855
2
gmid.h
2
gmid.h
|
@ -243,7 +243,7 @@ char *utf8_nth(char*, size_t);
|
|||
|
||||
/* iri.c */
|
||||
int parse_iri(char*, struct iri*, const char**);
|
||||
int trim_req_iri(char*);
|
||||
int trim_req_iri(char*, const char **);
|
||||
|
||||
/* puny.c */
|
||||
int puny_decode(const char*, char*, size_t);
|
||||
|
|
6
iri.c
6
iri.c
|
@ -364,12 +364,14 @@ parse_iri(char *iri, struct iri *ret, const char **err_ret)
|
|||
}
|
||||
|
||||
int
|
||||
trim_req_iri(char *iri)
|
||||
trim_req_iri(char *iri, const char **err)
|
||||
{
|
||||
char *i;
|
||||
|
||||
if ((i = strstr(iri, "\r\n")) == NULL)
|
||||
if ((i = strstr(iri, "\r\n")) == NULL) {
|
||||
*err = "missing CRLF";
|
||||
return 0;
|
||||
}
|
||||
*i = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
|
6
server.c
6
server.c
|
@ -308,8 +308,10 @@ handle_open_conn(struct pollfd *fds, struct client *c)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!trim_req_iri(c->req) || !parse_iri(c->req, &c->iri, &parse_err)) {
|
||||
start_reply(fds, c, BAD_REQUEST, parse_err);
|
||||
if (!trim_req_iri(c->req, &parse_err)
|
||||
|| !parse_iri(c->req, &c->iri, &parse_err)) {
|
||||
LOGI(c, "iri parse error: %s", parse_err);
|
||||
start_reply(fds, c, BAD_REQUEST, "invalid request");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue