On Sat, 10 Oct 2015, Michael McConville wrote:
> FWIW, this is a perfect use case for Coccinelle. Below is what I dredged
> up in src/usr.sbin (diff not yet carefully audited, but apparently
> sane).
I'm replying to this multiple times, cc'ing in the particular maintainers
as appropriate.
> --- smtpd/rfc2822.c
> +++ /tmp/cocci-output-29655-69b554-rfc2822.c
> @@ -93,13 +93,13 @@ parser_feed_header(struct rfc2822_parser
> char *pos;
>
> /* new header */
> - if (! isspace(*line) && *line != '\0') {
> + if (! isspace((unsigned char)*line) && *line != '\0') {
Yep
> - if (isspace(*(pos + 1)))
> + if (isspace((unsigned char)*(pos + 1)))
Again, array indexing reads better here, IMO:
if (isspace((unsigned char)pos[1])
> @@ -169,7 +169,7 @@ rfc2822_parser_feed(struct rfc2822_parse
> char buffer[RFC2822_MAX_LINE_SIZE+1];
>
> /* in header and line is not a continuation, execute callback */
> - if (rp->in_hdr && (*line == '\0' || !isspace(*line)))
> + if (rp->in_hdr && (*line == '\0' || !isspace((unsigned char)*line)))
Yep.
ok?
Philip Guenther
Index: usr.sbin/smtpd/rfc2822.c
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/rfc2822.c,v
retrieving revision 1.4
diff -u -p -r1.4 rfc2822.c
--- usr.sbin/smtpd/rfc2822.c 7 Sep 2015 15:36:53 -0000 1.4
+++ usr.sbin/smtpd/rfc2822.c 11 Oct 2015 02:37:03 -0000
@@ -93,13 +93,13 @@ parser_feed_header(struct rfc2822_parser
char *pos;
/* new header */
- if (! isspace(*line) && *line != '\0') {
+ if (! isspace((unsigned char)*line) && *line != '\0') {
rp->in_hdr = 1;
if ((pos = strchr(line, ':')) == NULL)
return 0;
memset(rp->header.name, 0, sizeof rp->header.name);
(void)memcpy(rp->header.name, line, pos - line);
- if (isspace(*(pos + 1)))
+ if (isspace((unsigned char)pos[1]))
return parser_feed_header(rp, pos + 1);
else {
*pos = ' ';
@@ -169,7 +169,7 @@ rfc2822_parser_feed(struct rfc2822_parse
char buffer[RFC2822_MAX_LINE_SIZE+1];
/* in header and line is not a continuation, execute callback */
- if (rp->in_hdr && (*line == '\0' || !isspace(*line)))
+ if (rp->in_hdr && (*line == '\0' || !isspace((unsigned char)*line)))
header_callback(rp);
/* no longer in headers */