On Tue, Feb 25, 2020 at 12:09:19AM +0100, Joerg Jung wrote:
> 
> > On 24. Feb 2020, at 20:31, Todd C. Miller <[email protected]> wrote:
> > 
> > I have a mostly-identical patch in my tree, though I tried to improve
> > readability a bit.
> 
> ok jung@
> 
> > - todd
> > 
> > Index: usr.sbin/smtpd/mta_session.c
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/smtpd/mta_session.c,v
> > retrieving revision 1.132
> > diff -u -p -u -r1.132 mta_session.c
> > --- usr.sbin/smtpd/mta_session.c    24 Feb 2020 16:16:07 -0000      1.132
> > +++ usr.sbin/smtpd/mta_session.c    24 Feb 2020 18:19:22 -0000
> > @@ -1295,13 +1295,12 @@ mta_io(struct io *io, int evt, void *arg
> >                     if (s->replybuf[0] == '\0')
> >                             (void)strlcat(s->replybuf, line, sizeof 
> > s->replybuf);
> >                     else if (len > 4) {
> > -                           line = line + 4;
> > -                           if (isdigit((int)*line) && *(line + 1) == '.' &&
> > -                               isdigit((int)*line+2) && *(line + 3) == '.' 
> > &&
> > -                               isdigit((int)*line+4) && 
> > isspace((int)*(line + 5)))
> > -                                   (void)strlcat(s->replybuf, line+5, 
> > sizeof s->replybuf);
> > -                           else
> > -                                   (void)strlcat(s->replybuf, line, sizeof 
> > s->replybuf);
> > +                           p = line + 4;
> > +                           if (isdigit((unsigned char)p[0]) && p[1] == '.' 
> > &&
> > +                               isdigit((unsigned char)p[2]) && p[3] == '.' 
> > &&
> > +                               isdigit((unsigned char)p[4]) && 
> > isspace((unsigned char)p[5]))
> > +                                   p += 5;
> > +                           (void)strlcat(s->replybuf, p, sizeof 
> > s->replybuf);
> >                     }
> >                     goto nextline;
> >             }
> > @@ -1313,9 +1312,9 @@ mta_io(struct io *io, int evt, void *arg
> >                     (void)strlcat(s->replybuf, line, sizeof s->replybuf);
> >             else if (len > 4) {
> >                     p = line + 4;
> > -                   if (isdigit((int)*p) && *(p + 1) == '.' &&
> > -                       isdigit((int)*p+2) && *(p + 3) == '.' &&
> > -                       isdigit((int)*p+4) && isspace((int)*(p + 5)))
> > +                   if (isdigit((unsigned char)p[0]) && p[1] == '.' &&
> > +                       isdigit((unsigned char)p[2]) && p[3] == '.' &&
> > +                       isdigit((unsigned char)p[4]) && isspace((unsigned 
> > char)p[5]))
> >                             p += 5;
> >                     if (strlcat(s->replybuf, p, sizeof s->replybuf) >= 
> > sizeof s->replybuf)
> >                             (void)strlcpy(s->replybuf, line, sizeof 
> > s->replybuf);
> > Index: usr.sbin/smtpd/parse.y
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/smtpd/parse.y,v
> > retrieving revision 1.276
> > diff -u -p -u -r1.276 parse.y
> > --- usr.sbin/smtpd/parse.y  3 Feb 2020 15:41:22 -0000       1.276
> > +++ usr.sbin/smtpd/parse.y  24 Feb 2020 18:19:51 -0000
> > @@ -529,7 +529,7 @@ SMTP LIMIT limits_smtp
> >             free($3);
> >             YYERROR;
> >     }
> > -   if (isspace((int)*$3) ||  !isprint((int)*$3) || *$3== '@') {
> > +   if (isspace((unsigned char)*$3) || !isprint((unsigned char)*$3) || *$3 
> > == '@') {
> >             yyerror("sub-addr-delim uses invalid character");
> >             free($3);
> >             YYERROR;
> > Index: usr.sbin/smtpd/smtp_client.c
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/smtpd/smtp_client.c,v
> > retrieving revision 1.12
> > diff -u -p -u -r1.12 smtp_client.c
> > --- usr.sbin/smtpd/smtp_client.c    10 Sep 2019 12:08:26 -0000      1.12
> > +++ usr.sbin/smtpd/smtp_client.c    24 Feb 2020 18:21:43 -0000
> > @@ -779,9 +779,10 @@ smtp_client_replycat(struct smtp_client 
> >             line += 3;
> >             if (line[0]) {
> >                     line += 1;
> > -                   if (isdigit((int)line[0]) && line[1] == '.' &&
> > -                       isdigit((int)line[2]) && line[3] == '.' &&
> > -                       isdigit((int)line[4]) && isspace((int)line[5]))
> > +                   if (isdigit((unsigned char)line[0]) && line[1] == '.' &&
> > +                       isdigit((unsigned char)line[2]) && line[3] == '.' &&
> > +                       isdigit((unsigned char)line[4]) &&
> > +                       isspace((unsigned char)line[5]))
> >                             line += 5;
> >             }
> >     } else
> > Index: usr.sbin/smtpd/util.c
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/smtpd/util.c,v
> > retrieving revision 1.150
> > diff -u -p -u -r1.150 util.c
> > --- usr.sbin/smtpd/util.c   3 Oct 2019 04:49:12 -0000       1.150
> > +++ usr.sbin/smtpd/util.c   24 Feb 2020 19:17:12 -0000
> > @@ -462,7 +462,7 @@ valid_domainpart(const char *s)
> >             if (strlcpy(domain, p, sizeof domain) >= sizeof domain)
> >                     return 0;
> > 
> > -           c = strchr(domain, (int)']');
> > +           c = strchr(domain, ']');
> >             if (!c || c[1] != '\0')
> >                     return 0;
> > 
> > @@ -489,7 +489,7 @@ valid_domainpart(const char *s)
> >     return res_hnok(s);
> > }
> > 
> > -#define LABELCHR(c) ((c) == '-' || (c) == '_' || isalpha((int)(c)) || 
> > isdigit((int)(c)))
> > +#define LABELCHR(c) ((c) == '-' || (c) == '_' || isalpha((unsigned 
> > char)(c)) || isdigit((unsigned char)(c)))
> > #define LABELMAX 63
> > #define DNAMEMAX 253
> > 
> > 
> 

Hi,

Below is a patch which adds some missing casts:


diff --git usr.sbin/smtpd/mail.lmtp.c usr.sbin/smtpd/mail.lmtp.c
index f427e73dc35..c7dc46d5ec3 100644
--- usr.sbin/smtpd/mail.lmtp.c
+++ usr.sbin/smtpd/mail.lmtp.c
@@ -255,9 +255,9 @@ lmtp_engine(int fd_read, struct session *session)
                line[strcspn(line, "\r")] = '\0';
 
                if (linelen < 4 ||
-                   !isdigit(line[0]) ||
-                   !isdigit(line[1]) ||
-                   !isdigit(line[2]) ||
+                   !isdigit((unsigned char)line[0]) ||
+                   !isdigit((unsigned char)line[1]) ||
+                   !isdigit((unsigned char)line[2]) ||
                    (line[3] != ' ' && line[3] != '-'))
                        errx(EX_TEMPFAIL, "LMTP server sent an invalid line");
 
diff --git usr.sbin/smtpd/smtp_session.c usr.sbin/smtpd/smtp_session.c
index 87ae18a6667..18b0c3fc6d3 100644
--- usr.sbin/smtpd/smtp_session.c
+++ usr.sbin/smtpd/smtp_session.c
@@ -452,7 +452,7 @@ header_address_rewrite_buffer(char *buffer, const char 
*address, size_t len)
                        pos_component_beg = 0;
                else {
                        for (pos_component_beg = pos_component_end; 
pos_component_beg >= 0; --pos_component_beg)
-                               if (buffer[pos_component_beg] == ')' || 
isspace(buffer[pos_component_beg]))
+                               if (buffer[pos_component_beg] == ')' || 
isspace((unsigned char)buffer[pos_component_beg]))
                                        break;
                        pos_component_beg += 1;
                        pos_component_end += 1;
diff --git usr.sbin/smtpd/spfwalk.c usr.sbin/smtpd/spfwalk.c
index 97104eb9105..130c7221fb0 100644
--- usr.sbin/smtpd/spfwalk.c
+++ usr.sbin/smtpd/spfwalk.c
@@ -95,7 +95,7 @@ spfwalk(int argc, struct parameter *argv)
        tgt.dispatch = dispatch_txt;
 
        while ((linelen = getline(&line, &linesize, stdin)) != -1) {
-               while (linelen-- > 0 && isspace(line[linelen]))
+               while (linelen-- > 0 && isspace((unsigned char)line[linelen]))
                        line[linelen] = '\0';
 
                if (linelen > 0)

-- 
Kind regards,
Hiltjo

Reply via email to