Commit f8d30e17 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0be25253
...@@ -135,9 +135,8 @@ error _WatchLink::_serveRX(context::Context ctx) { ...@@ -135,9 +135,8 @@ error _WatchLink::_serveRX(context::Context ctx) {
while (1) { while (1) {
// NOTE: .close() makes sure .f.read*() will wake up // NOTE: .close() makes sure .f.read*() will wake up
//printf("serveRX -> readline ...\n"); tie(l, err) = wlink._readline();
tie(l, err) = wlink._readline(); // XXX +maxlen //trace(" readline -> l='%s' ; err='%s'\n", v(l), v(err));
//printf(" readline -> woken up; l='%s' ; err='%s'\n", v(l), v(err));
if (err == io::EOF_) { // peer closed its tx if (err == io::EOF_) { // peer closed its tx
// XXX what happens on other errors? // XXX what happens on other errors?
wlink.rx_eof.close(); wlink.rx_eof.close();
...@@ -416,19 +415,21 @@ tuple<string, error> _WatchLink::_readline() { ...@@ -416,19 +415,21 @@ tuple<string, error> _WatchLink::_readline() {
if (nl != string::npos) { if (nl != string::npos) {
auto line = wlink._rxbuf.substr(0, nl+1); auto line = wlink._rxbuf.substr(0, nl+1);
wlink._rxbuf = wlink._rxbuf.substr(nl+1); wlink._rxbuf = wlink._rxbuf.substr(nl+1);
//printf("\t_readline -> ret '%s'\n", v(line)); //trace("\t_readline -> ret '%s'\n", v(line));
return make_tuple(line, nil); return make_tuple(line, nil);
} }
nl_searchfrom = wlink._rxbuf.length(); nl_searchfrom = wlink._rxbuf.length();
int n; int n;
error err; error err;
//printf("\t_readline -> read ...\n"); //trace("\t_readline -> read ...\n");
tie(n, err) = wlink._f->read(buf, sizeof(buf)); tie(n, err) = wlink._f->read(buf, sizeof(buf));
//printf("\t_readline -> read: n=%d err='%s'\n", n, v(err)); //trace("\t_readline -> read: n=%d err='%s'\n", n, v(err));
if (n > 0) { if (n > 0) {
// XXX limit line length to avoid DoS
wlink._rxbuf += string(buf, n); wlink._rxbuf += string(buf, n);
// limit line length to avoid DoS
if (wlink._rxbuf.length() > 128) // XXX limit arbitrary
return make_tuple("", fmt::errorf("line is too long"));
continue; continue;
} }
if (err == nil) if (err == nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment