Skip to content

Commit

Permalink
nnrpd: Reject articles with invalid dot-stuffing
Browse files Browse the repository at this point in the history
Enforce correctly formatted articles at injection time.

close #286
  • Loading branch information
Julien-Elie committed Dec 9, 2023
1 parent 720a6f9 commit ef575f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/pod/news.pod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ preserves the leading initial dot at injection time).

=item *

B<nnrpd> now rejects articles with invalid dot-stuffing (that is to say when
a dot at the beginning of a line is not doubled) as it is a violation of the
NNTP protocol. (B<innd> still goes on accepting and propagating such articles
as they have already been injected and propagated.)

=item *

Fixed the computation of the Bytes header field by B<pullnews> (in header-only
mode with the B<-B> flag).

Expand Down
17 changes: 14 additions & 3 deletions nnrpd/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ CMDpost(int ac, char *av[])
static int size;
char *p, *q;
char *end;
int longline;
int longline, missingdotstuffing;
READTYPE r;
int i;
long l;
Expand Down Expand Up @@ -748,6 +748,7 @@ CMDpost(int ac, char *av[])
end = &article[size];

longline = 0;
missingdotstuffing = 0;
for (l = 1;; l++) {
size_t len;
const char *line;
Expand Down Expand Up @@ -797,18 +798,20 @@ CMDpost(int ac, char *av[])
p = i + article;
}

/* Reverse any byte-stuffing. */
/* Reverse any dot-stuffing. */
if (*line == '.') {
++line;
--len;
if (*line != '.' && missingdotstuffing == 0)
missingdotstuffing = l;
}
memcpy(p, line, len);
p += len;
*p++ = '\n';
*p = '\0';
}

if (longline) {
if (longline > 0) {
warn("%s too long in post", Client.host);
Reply("%d Line %d too long\r\n",
ihave ? NNTP_FAIL_IHAVE_REJECT : NNTP_FAIL_POST_REJECT,
Expand All @@ -817,6 +820,14 @@ CMDpost(int ac, char *av[])
return;
}

if (missingdotstuffing > 0) {
Reply("%d Line %d without its initial dot doubled (dot-stuffing)\r\n",
ihave ? NNTP_FAIL_IHAVE_REJECT : NNTP_FAIL_POST_REJECT,
missingdotstuffing);
POSTrejected++;
return;
}

/* Send the article to the server. */
response = ARTpost(article, idbuff, &permanent);
if (response == NULL) {
Expand Down

0 comments on commit ef575f8

Please sign in to comment.