59.html: fix typo

2016-03-05 Thread Serguey Parkhomovsky
This fixes a small typo in the release notes for 5.9.

Index: 59.html
===
RCS file: /cvs/www/59.html,v
retrieving revision 1.55
diff -u -r1.55 59.html
--- 59.html 5 Mar 2016 03:25:49 -   1.55
+++ 59.html 5 Mar 2016 21:58:56 -
@@ -191,7 +191,7 @@
   is a little friendlier to use.
 Updated
   http://www.openbsd.org/cgi-bin/man.cgi?query=flex&sektion=1";>flex(1).
-Forked http://www.openbsd.org/cgi-bin/man.cgi?query=less&sektion=1";>less(1)
 from upstream, then proceeeded to clean it up substantially.
+Forked http://www.openbsd.org/cgi-bin/man.cgi?query=less&sektion=1";>less(1)
 from upstream, then proceeded to clean it up substantially.
 http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/macppc/pdisk.8?query=pdisk";>pdisk(8)
 was largely rewritten and pledged.
 Renaming files in the root directory of a MSDOS filesystem was fixed.
 Many obsolete http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/disktab.5?query=disktab";>disktab(5)
 attributes and entries were removed.



[patch] smtpctl(8): fix mail queueing

2015-12-22 Thread Serguey Parkhomovsky
Rev 1.141 of smtpctl.c killed mail queueing for me:

$ echo "test" | mail -s test sparkhom
$ send-mail: unknown option -- i
send-mail: unknown option -- t
send-mail: no recipients

The sendmail option parsing that was added eats the recipient list. I
have attached a patch that fixes this issue, and also quiets the getopt
"unknown option" errors, as most options are processed later.

Index: smtpctl.c
===
RCS file: /cvs/src/usr.sbin/smtpd/smtpctl.c,v
retrieving revision 1.142
diff -u -p -r1.142 smtpctl.c
--- smtpctl.c   22 Dec 2015 15:59:10 -  1.142
+++ smtpctl.c   22 Dec 2015 20:37:48 -
@@ -990,6 +990,7 @@ main(int argc, char **argv)
 * determine whether we are called with flags
 * that should invoke makemap/newaliases.
 */
+   opterr = 0;
while ((ch = getopt(argc, argv, "b:C:O:")) != -1) {
switch (ch) {
case 'b':
@@ -1006,10 +1007,13 @@ main(int argc, char **argv)
break;
}
}
-   argc -= optind;
-   argv += optind;
-   optind = 0;
+   opterr = 1;
+
if (sendmail_makemap) {
+   argc -= optind;
+   argv += optind;
+   optind = 0;
+
memset(&args, 0, sizeof args);
addargs(&args, "%s", "makemap");
for (i = 0; i < argc; i++)
@@ -1021,6 +1025,7 @@ main(int argc, char **argv)
 
return makemap(args.num, args.list);
}
+   optind = 0;
 
if (!srv_connect())
offlinefp = offline_file();



[patch] smtpd.conf.5: change examples to use file backend

2015-12-22 Thread Serguey Parkhomovsky
Since the default backend for the aliases table was recently changed
from db to file, change the examples in smtpd.conf.5 to use the file
backend as well.

Index: smtpd.conf.5
===
RCS file: /cvs/src/usr.sbin/smtpd/smtpd.conf.5,v
retrieving revision 1.147
diff -u -p -r1.147 smtpd.conf.5
--- smtpd.conf.515 Dec 2015 23:16:13 -  1.147
+++ smtpd.conf.522 Dec 2015 17:01:40 -
@@ -1019,15 +1019,14 @@ A secrets file is needed to specify a us
 # chmod 640 /etc/mail/secrets
 # chown root:_smtpd /etc/mail/secrets
 # echo "label username:password" > /etc/mail/secrets
-# makemap /etc/mail/secrets
 .Ed
 .Pp
 .Nm
 would look like this:
 .Bd -literal -offset indent
 listen on lo0
-table aliases db:/etc/mail/aliases.db
-table secrets db:/etc/mail/secrets.db
+table aliases file:/etc/mail/aliases
+table secrets file:/etc/mail/secrets
 accept for local alias  deliver to mbox
 accept for any relay via tls+auth://la...@smtp.example.com \e
auth 
@@ -1058,7 +1057,7 @@ pki mail.example.com key "/etc/ssl/priva
 listen on lo0
 listen on egress tls pki mail.example.com auth
 
-table aliases db:/etc/mail/aliases.db
+table aliases file:/etc/mail/aliases
 
 accept for local alias  deliver to mda "/path/to/mda \-f \-"
 accept from any for domain example.com \e
@@ -1077,7 +1076,7 @@ The signed messages are received on port
 listen on lo0
 listen on lo0 port 10028 tag DKIM
 
-table aliases db:/etc/mail/aliases.db
+table aliases file:/etc/mail/aliases
 
 accept for local alias  deliver to mbox
 accept tagged DKIM for any relay
@@ -1095,7 +1094,7 @@ originate mail with your domain as the s
 listen on lo0
 listen on egress
 
-table aliases   db:/etc/mail/aliases.db
+table aliases file:/etc/mail/aliases
 table other-relays "/etc/mail/other-relays"
 
 accept for local alias  deliver to mbox



Re: [patch] mailwrapper(8): remove unneeded argument in addarg

2015-12-21 Thread Serguey Parkhomovsky
Ping?

On Mon, Dec 14, 2015 at 09:24:21AM -0800, Serguey Parkhomovsky wrote:
> This patch removes the copy argument to addarg, which is unneeded. No
> functional change.
> 
> Index: mailwrapper.c
> ===
> RCS file: /cvs/src/usr.sbin/mailwrapper/mailwrapper.c,v
> retrieving revision 1.21
> diff -u -p -r1.21 mailwrapper.c
> --- mailwrapper.c 14 Dec 2015 02:56:07 -  1.21
> +++ mailwrapper.c 14 Dec 2015 16:42:14 -
> @@ -51,7 +51,7 @@ struct arglist {
>  int main(int, char *[], char *[]);
>  
>  static void initarg(struct arglist *);
> -static void addarg(struct arglist *, const char *, int);
> +static void addarg(struct arglist *, const char *);
>  
>  extern const char *__progname;   /* from crt0.o */
>  
> @@ -65,7 +65,7 @@ initarg(struct arglist *al)
>  }
>  
>  static void
> -addarg(struct arglist *al, const char *arg, int copy)
> +addarg(struct arglist *al, const char *arg)
>  {
>   if (al->argc == al->maxc) {
>   al->maxc <<= 1;
> @@ -73,11 +73,8 @@ addarg(struct arglist *al, const char *a
>   if (al->argv == NULL)
>   err(1, "realloc");
>   }
> - if (copy) {
> - if ((al->argv[al->argc++] = strdup(arg)) == NULL)
> - err(1, "strdup");
> - } else
> - al->argv[al->argc++] = (char *)arg;
> +
> + al->argv[al->argc++] = (char *)arg;
>  }
>  
>  int
> @@ -98,7 +95,7 @@ main(int argc, char *argv[], char *envp[
>  
>   initarg(&al);
>   for (len = 0; len < argc; len++)
> - addarg(&al, argv[len], 0);
> + addarg(&al, argv[len]);
>  
>   config = fopen(_PATH_MAILERCONF, "r");
>  
> @@ -106,7 +103,7 @@ main(int argc, char *argv[], char *envp[
>   err(1, "pledge");
>  
>   if (config == NULL) {
> - addarg(&al, NULL, 0);
> + addarg(&al, NULL);
>   openlog(__progname, LOG_PID, LOG_MAIL);
>   syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
>   _PATH_MAILERCONF, _PATH_DEFAULTMTA);
> @@ -145,7 +142,7 @@ main(int argc, char *argv[], char *envp[
>   for (ap = strsep(&cp, WS); ap != NULL;
>   ap = strsep(&cp, WS))
>   if (*ap)
> - addarg(&al, ap, 0);
> + addarg(&al, ap);
>   break;
>   }
>  
> @@ -154,7 +151,7 @@ main(int argc, char *argv[], char *envp[
>  
>   (void)fclose(config);
>  
> - addarg(&al, NULL, 0);
> + addarg(&al, NULL);
>  
>   execve(to, al.argv, envp);
>   err(1, "cannot exec %s", to);



Re: [patch] nlist(3): out of bounds read

2015-12-21 Thread Serguey Parkhomovsky
Ping? This is the same sanity check that's done in nm(1)'s ELF handling.

On Thu, Dec 10, 2015 at 09:40:11AM -0800, Serguey Parkhomovsky wrote:
> When dealing with a malformed ELF header, e_shentsize may be 0. This
> causes an out of bounds read while finding the symbol table on line 141.
> 
> Found using afl.
> 
> Index: nlist.c
> ===
> RCS file: /cvs/src/lib/libc/gen/nlist.c,v
> retrieving revision 1.65
> diff -u -p -r1.65 nlist.c
> --- nlist.c   16 Oct 2015 16:54:38 -  1.65
> +++ nlist.c   10 Dec 2015 16:36:26 -
> @@ -102,6 +102,10 @@ __fdnlist(int fd, struct nlist *list)
>   !__elf_is_okay__(&ehdr) || fstat(fd, &st) < 0)
>   return (-1);
>  
> + /* Make sure section header size is not too small */
> + if (ehdr.e_shentsize < sizeof(Elf_Shdr))
> + return (-1);
> +
>   /* calculate section header table size */
>   shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
>  



[patch] mailwrapper(8): remove unneeded argument in addarg

2015-12-14 Thread Serguey Parkhomovsky
This patch removes the copy argument to addarg, which is unneeded. No
functional change.

Index: mailwrapper.c
===
RCS file: /cvs/src/usr.sbin/mailwrapper/mailwrapper.c,v
retrieving revision 1.21
diff -u -p -r1.21 mailwrapper.c
--- mailwrapper.c   14 Dec 2015 02:56:07 -  1.21
+++ mailwrapper.c   14 Dec 2015 16:42:14 -
@@ -51,7 +51,7 @@ struct arglist {
 int main(int, char *[], char *[]);
 
 static void initarg(struct arglist *);
-static void addarg(struct arglist *, const char *, int);
+static void addarg(struct arglist *, const char *);
 
 extern const char *__progname; /* from crt0.o */
 
@@ -65,7 +65,7 @@ initarg(struct arglist *al)
 }
 
 static void
-addarg(struct arglist *al, const char *arg, int copy)
+addarg(struct arglist *al, const char *arg)
 {
if (al->argc == al->maxc) {
al->maxc <<= 1;
@@ -73,11 +73,8 @@ addarg(struct arglist *al, const char *a
if (al->argv == NULL)
err(1, "realloc");
}
-   if (copy) {
-   if ((al->argv[al->argc++] = strdup(arg)) == NULL)
-   err(1, "strdup");
-   } else
-   al->argv[al->argc++] = (char *)arg;
+
+   al->argv[al->argc++] = (char *)arg;
 }
 
 int
@@ -98,7 +95,7 @@ main(int argc, char *argv[], char *envp[
 
initarg(&al);
for (len = 0; len < argc; len++)
-   addarg(&al, argv[len], 0);
+   addarg(&al, argv[len]);
 
config = fopen(_PATH_MAILERCONF, "r");
 
@@ -106,7 +103,7 @@ main(int argc, char *argv[], char *envp[
err(1, "pledge");
 
if (config == NULL) {
-   addarg(&al, NULL, 0);
+   addarg(&al, NULL);
openlog(__progname, LOG_PID, LOG_MAIL);
syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
_PATH_MAILERCONF, _PATH_DEFAULTMTA);
@@ -145,7 +142,7 @@ main(int argc, char *argv[], char *envp[
for (ap = strsep(&cp, WS); ap != NULL;
ap = strsep(&cp, WS))
if (*ap)
-   addarg(&al, ap, 0);
+   addarg(&al, ap);
break;
}
 
@@ -154,7 +151,7 @@ main(int argc, char *argv[], char *envp[
 
(void)fclose(config);
 
-   addarg(&al, NULL, 0);
+   addarg(&al, NULL);
 
execve(to, al.argv, envp);
err(1, "cannot exec %s", to);



[patch] nlist(3): out of bounds read

2015-12-10 Thread Serguey Parkhomovsky
When dealing with a malformed ELF header, e_shentsize may be 0. This
causes an out of bounds read while finding the symbol table on line 141.

Found using afl.

Index: nlist.c
===
RCS file: /cvs/src/lib/libc/gen/nlist.c,v
retrieving revision 1.65
diff -u -p -r1.65 nlist.c
--- nlist.c 16 Oct 2015 16:54:38 -  1.65
+++ nlist.c 10 Dec 2015 16:36:26 -
@@ -102,6 +102,10 @@ __fdnlist(int fd, struct nlist *list)
!__elf_is_okay__(&ehdr) || fstat(fd, &st) < 0)
return (-1);
 
+   /* Make sure section header size is not too small */
+   if (ehdr.e_shentsize < sizeof(Elf_Shdr))
+   return (-1);
+
/* calculate section header table size */
shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
 



Re: [patch] mailwrapper: remove broken fallback code

2015-12-08 Thread Serguey Parkhomovsky
On Tue, Dec 08, 2015 at 10:39:56AM +0100, Sunil Nimmagadda wrote:
> > If /etc/mailer.conf doesn't exist, mailwrapper tries to run sendmail,
> > giving a confusing error message:
> > 
> > mailwrapper: cannot exec /usr/libexec/sendmail/sendmail: No such
> > file or directory
> > 
> > This patch removes this fallback code. I believe this is cleaner than
> > updating the fallback since we would have to put two paths in: one for
> > sendmail/send-mail/mailq and one for makemap/newaliases.
> 
> I am not sure about removing the fallback code but if we decide to
> keep it, this diff should fix the fallback case.

Good catch; I didn't realize you could also call newaliases/makemap
through /usr/sbin/smtpctl.

If we choose to keep the fallback code, we should probably fix the
manpage for mailwrapper as well. I've attached a revised version of your
patch that documents the fallback behavior.

Index: mailwrapper.8
===
RCS file: /cvs/src/usr.sbin/mailwrapper/mailwrapper.8,v
retrieving revision 1.12
diff -u -p -r1.12 mailwrapper.8
--- mailwrapper.8   27 Mar 2014 22:34:42 -  1.12
+++ mailwrapper.8   8 Dec 2015 16:32:01 -
@@ -120,9 +120,11 @@ is typically set up as a symlink to
 which is not usually invoked on its own.
 .Sh DIAGNOSTICS
 .Nm
-will return an error value and print a diagnostic if its configuration
-file is missing or malformed, or does not contain a mapping for the
-name under which
+will invoke
+.Xr smtpd 8
+if its configuration file is missing.
+It will return an error value and print a diagnostic if its configuration
+file is malformed, or does not contain a mapping for the name under which
 .Nm
 was invoked.
 .Sh SEE ALSO
Index: mailwrapper.c
===
RCS file: /cvs/src/usr.sbin/mailwrapper/mailwrapper.c,v
retrieving revision 1.20
diff -u -p -r1.20 mailwrapper.c
--- mailwrapper.c   12 Oct 2015 22:01:08 -  1.20
+++ mailwrapper.c   8 Dec 2015 16:32:01 -
@@ -41,7 +41,7 @@
 #include 
 
 #define _PATH_MAILERCONF   "/etc/mailer.conf"
-#define _PATH_DEFAULTMTA   "/usr/libexec/sendmail/sendmail"
+#define _PATH_DEFAULTMTA   "/usr/sbin/smtpctl"
 
 struct arglist {
size_t argc, maxc;



[patch] mailwrapper: remove broken fallback code

2015-12-07 Thread Serguey Parkhomovsky
If /etc/mailer.conf doesn't exist, mailwrapper tries to run sendmail,
giving a confusing error message:

mailwrapper: cannot exec /usr/libexec/sendmail/sendmail: No such
file or directory

This patch removes this fallback code. I believe this is cleaner than
updating the fallback since we would have to put two paths in: one for
sendmail/send-mail/mailq and one for makemap/newaliases.

Index: mailwrapper.c
===
RCS file: /cvs/src/usr.sbin/mailwrapper/mailwrapper.c,v
retrieving revision 1.20
diff -u -p -r1.20 mailwrapper.c
--- mailwrapper.c   12 Oct 2015 22:01:08 -  1.20
+++ mailwrapper.c   7 Dec 2015 21:33:57 -
@@ -36,12 +36,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
 #define _PATH_MAILERCONF   "/etc/mailer.conf"
-#define _PATH_DEFAULTMTA   "/usr/libexec/sendmail/sendmail"
 
 struct arglist {
size_t argc, maxc;
@@ -100,21 +98,11 @@ main(int argc, char *argv[], char *envp[
for (len = 0; len < argc; len++)
addarg(&al, argv[len], 0);
 
-   config = fopen(_PATH_MAILERCONF, "r");
+   if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL)
+   err(1, "cannot open %s", _PATH_MAILERCONF);
 
if (pledge("stdio exec", NULL) == -1)
err(1, "pledge");
-
-   if (config == NULL) {
-   addarg(&al, NULL, 0);
-   openlog(__progname, LOG_PID, LOG_MAIL);
-   syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
-   _PATH_MAILERCONF, _PATH_DEFAULTMTA);
-   closelog();
-   execve(_PATH_DEFAULTMTA, al.argv, envp);
-   err(1, "cannot exec %s", _PATH_DEFAULTMTA);
-   /*NOTREACHED*/
-   }
 
for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {



[patch] dvmrpd: strings header cleanup

2015-12-07 Thread Serguey Parkhomovsky
Fixes implicit memcpy declarations by using string.h instead of
strings.h, and removes strings.h from files that don't need it. Also,
change bzero(3) to memset(3).

Index: ask_nbrs2.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/ask_nbrs2.c,v
retrieving revision 1.4
diff -u -p -r1.4 ask_nbrs2.c
--- ask_nbrs2.c 5 May 2015 01:26:37 -   1.4
+++ ask_nbrs2.c 7 Dec 2015 18:20:06 -
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
Index: control.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/control.c,v
retrieving revision 1.21
diff -u -p -r1.21 control.c
--- control.c   5 Dec 2015 13:11:00 -   1.21
+++ control.c   7 Dec 2015 18:20:06 -
@@ -52,7 +52,7 @@ control_init(void)
return (-1);
}
 
-   bzero(&sun, sizeof(sun));
+   memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strlcpy(sun.sun_path, DVMRPD_SOCKET, sizeof(sun.sun_path));
 
Index: graft.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/graft.c,v
retrieving revision 1.4
diff -u -p -r1.4 graft.c
--- graft.c 5 May 2015 01:26:37 -   1.4
+++ graft.c 7 Dec 2015 18:20:06 -
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
Index: graft_ack.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/graft_ack.c,v
retrieving revision 1.4
diff -u -p -r1.4 graft_ack.c
--- graft_ack.c 5 May 2015 01:26:37 -   1.4
+++ graft_ack.c 7 Dec 2015 18:20:06 -
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
Index: igmp.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/igmp.c,v
retrieving revision 1.3
diff -u -p -r1.3 igmp.c
--- igmp.c  18 Nov 2014 20:54:28 -  1.3
+++ igmp.c  7 Dec 2015 18:20:06 -
@@ -51,7 +51,7 @@ send_igmp_query(struct iface *iface, str
fatal("send_igmp_query");
 
/* IGMP header */
-   bzero(&igmp_hdr, sizeof(igmp_hdr));
+   memset(&igmp_hdr, 0, sizeof(igmp_hdr));
igmp_hdr.type = PKT_TYPE_MEMBER_QUERY;
 
if (group == NULL) {
Index: kroute.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/kroute.c,v
retrieving revision 1.12
diff -u -p -r1.12 kroute.c
--- kroute.c27 Sep 2015 17:29:46 -  1.12
+++ kroute.c7 Dec 2015 18:20:06 -
@@ -136,7 +136,7 @@ kif_find(int ifindex)
 {
struct kif_node s;
 
-   bzero(&s, sizeof(s));
+   memset(&s, 0, sizeof(s));
s.k.ifindex = ifindex;
 
return (RB_FIND(kif_tree, &kit, &s));
Index: nbrs2.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/nbrs2.c,v
retrieving revision 1.4
diff -u -p -r1.4 nbrs2.c
--- nbrs2.c 5 May 2015 01:26:37 -   1.4
+++ nbrs2.c 7 Dec 2015 18:20:06 -
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
Index: packet.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/packet.c,v
retrieving revision 1.3
diff -u -p -r1.3 packet.c
--- packet.c25 Oct 2014 03:23:49 -  1.3
+++ packet.c7 Dec 2015 18:20:07 -
@@ -28,7 +28,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
@@ -48,7 +48,7 @@ gen_dvmrp_hdr(struct ibuf *buf, struct i
 {
struct dvmrp_hdrdvmrp_hdr;
 
-   bzero(&dvmrp_hdr, sizeof(dvmrp_hdr));
+   memset(&dvmrp_hdr, 0, sizeof(dvmrp_hdr));
dvmrp_hdr.type = PKT_TYPE_DVMRP;
dvmrp_hdr.code = code;
dvmrp_hdr.chksum = 0;   /* updated later */
Index: prune.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/prune.c,v
retrieving revision 1.5
diff -u -p -r1.5 prune.c
--- prune.c 5 May 2015 01:26:37 -   1.5
+++ prune.c 7 Dec 2015 18:20:07 -
@@ -23,7 +23,7 @@
 #include 
 
 #include 
-#include 
+#include 
 
 #include "igmp.h"
 #include "dvmrpd.h"
@@ -47,7 +47,7 @@ send_prune(struct nbr *nbr, struct prune
if (nbr->iface->passive)
return (0);
 
-   bzero(&prune, sizeof(prune));
+   memset(&prune, 0, sizeof(prune));
 
dst.sin_family = AF_INET;
dst.sin_len = sizeof(struct sockaddr_in);
@@ -97,7 +97,7 @@ recv_prune(struct nbr *nbr, char *buf, u
return;
}
 
-   bzero(&p, sizeof(p));
+   memset(&p, 0, sizeof(p));
 
prune = (struct prune_hdr *)buf;
 
Index: rde_mfc.c
===
RCS file: /cvs/src/usr.sbin/dvmrpd/rde_mfc.c,v
retrieving revision 1.9
diff -u -p -r1.9 rde_mfc.c
--- rde_mfc.c   6 Apr 2011 11:36:26 -   1.9
+++ rde_mfc.c   7 Dec 2015 18:20:07 -
@@ -251,7 +251,7 @@ mfc_send_prune(struct rt_node *rn, struc
 {
struct prunep;
 
-   bzero(&p, si

Re: [Flex-devel] Index underflow in lex(1)

2015-11-30 Thread Serguey Parkhomovsky
On Mon, Nov 30, 2015 at 06:51:39PM -0500, Will Estes wrote:
> Awesome. This applies cleanly albeit with fuzz and makes sense.
> 
> Could you provide Serguey Parkhomovsky's email address so I can use it when 
> committing the change into git?

Happy to help. :-)

The address that I'm sending from right now is OK. As well, I believe
this patch fixes #193 and #194 in flex's bugtracker.



Re: Index underflow in lex(1)

2015-11-30 Thread Serguey Parkhomovsky
On Thu, Nov 26, 2015 at 01:03:22PM -0500, Michael McConville wrote:
> This nondeterministically underflows _sf_top_ix, causing a segfault:
> 
>   http://www.sccs.swarthmore.edu/users/16/mmcconv1/dump/crash.l
> 

Looks like _sf_top_ix always underflows whenever there are extra closing
parentheses in the rules section. The nondeterministic behavior is
probably heap layout related.

I've taken your suggestion and updated scan.l to give a syntax error
when there is an unbalanced parenthesis, which fixes the issue:

Index: scan.l
===
RCS file: /cvs/src/usr.bin/lex/scan.l,v
retrieving revision 1.12
diff -u -p -r1.12 scan.l
--- scan.l  19 Nov 2015 23:34:56 -  1.12
+++ scan.l  30 Nov 2015 21:19:44 -
@@ -741,7 +741,13 @@ nmstr[yyleng - 2 - end_is_ws] = '\0';  /
 return '(';
 }
 "(" sf_push(); return '(';
-")" sf_pop(); return ')';
+")" {
+if (_sf_top_ix > 0) {
+sf_pop();
+return ')';
+} else
+synerr(_("unbalanced parenthesis"));
+}
 
[/|*+?.(){}]return (unsigned char) yytext[0];
.   RETURNCHAR;



Re: [patch] gprof(1): fix incompatible pointer types

2015-11-30 Thread Serguey Parkhomovsky
Ping?

On Mon, Nov 16, 2015 at 10:09:29AM -0800, Serguey Parkhomovsky wrote:
> Hi Philip,
> 
> Thanks for the detailed explanation on comparison functions for qsort. I
> have looked through your changes, and have only found one issue:
> 
> > 2) totalcmp(A,B) and totalcmp(B,A) both return <0 if both A and B have 
> >name==0 and cycleno!=0, and they both return >0 if both A and B have 
> >naem==0 and cycleno==0, violating the consistency requirement.
> 
> The logic is still not quite right with totalcmp; it is still
> inconsistent where both A and B have:
> * name == 0 && cycleno == 0 (both return -1)
> * name != 0 && cycleno == 0 (both return -1)
> * name != 0 && cycleno != 0 (both return -1)
> 
> As well, if name == 0 && cycleno != 0, the code will drop through and
> there will be a null pointer dereference:
> 
> if ( *(np1 -> name) != '_' && *(np2 -> name) == '_' )
>   return -1;
> if ( *(np1 -> name) == '_' && *(np2 -> name) != '_' )
>   return 1;
> 
> What do you think of the following diff? I've put some of the boolean logic
> into variables to enhance readability.
> 
> Index: arcs.c
> ===
> RCS file: /cvs/src/usr.bin/gprof/arcs.c,v
> retrieving revision 1.13
> diff -u -p -u -r1.13 arcs.c
> --- arcs.c20 Aug 2015 22:32:41 -  1.13
> +++ arcs.c16 Nov 2015 17:41:55 -
> @@ -95,9 +95,14 @@ addarc(nltype *parentp, nltype *childp, 
>  nltype   **topsortnlp;
>  
>  int
> -topcmp(nltype **npp1, nltype **npp2)
> +topcmp(const void *v1, const void *v2)
>  {
> -return (*npp1) -> toporder - (*npp2) -> toporder;
> +const nltype * const *npp1 = v1;
> +const nltype * const *npp2 = v2;
> +
> +if ((*npp1) -> toporder < (*npp2) -> toporder)
> + return -1;
> +return (*npp1) -> toporder > (*npp2) -> toporder;
>  }
>  
>  nltype **
> Index: gprof.h
> ===
> RCS file: /cvs/src/usr.bin/gprof/gprof.h,v
> retrieving revision 1.14
> diff -u -p -u -r1.14 gprof.h
> --- gprof.h   19 Oct 2013 13:51:40 -  1.14
> +++ gprof.h   16 Nov 2015 17:41:55 -
> @@ -281,10 +281,10 @@ voidsortchildren(nltype *);
>  void sortmembers(nltype *);
>  void sortparents(nltype *);
>  void tally(struct rawarc *);
> -int  timecmp(nltype **, nltype **);
> +int  timecmp(const void *, const void *);
>  void timepropagate(nltype *);
> -int  topcmp(nltype **, nltype **);
> -int  totalcmp(nltype **, nltype **);
> +int  topcmp(const void *, const void *);
> +int  totalcmp(const void *, const void *);
>  
>  #define  LESSTHAN-1
>  #define  EQUALTO 0
> Index: printgprof.c
> ===
> RCS file: /cvs/src/usr.bin/gprof/printgprof.c,v
> retrieving revision 1.13
> diff -u -p -u -r1.13 printgprof.c
> --- printgprof.c  20 Aug 2015 22:32:41 -  1.13
> +++ printgprof.c  16 Nov 2015 17:41:55 -
> @@ -35,7 +35,7 @@
>  #include "gprof.h"
>  #include "pathnames.h"
>  
> -int namecmp(nltype **, nltype **);
> +int namecmp(const void *, const void *);
>  
>  void
>  printprof()
> @@ -66,21 +66,19 @@ printprof()
>  }
>  
>  int
> -timecmp(nltype **npp1, nltype **npp2)
> +timecmp(const void *v1, const void *v2)
>  {
> -double   timediff;
> -long calldiff;
> +const nltype * const *npp1 = v1;
> +const nltype * const *npp2 = v2;
>  
> -timediff = (*npp2) -> time - (*npp1) -> time;
> -if ( timediff > 0.0 )
> +if ((*npp2) -> time < (*npp1) -> time)
> + return -1;
> +if ((*npp2) -> time > (*npp1) -> time)
>   return 1 ;
> -if ( timediff < 0.0 )
> +if ((*npp2) -> ncall < (*npp1) -> ncall)
>   return -1;
> -calldiff = (*npp2) -> ncall - (*npp1) -> ncall;
> -if ( calldiff > 0 )
> +if ((*npp2) -> ncall > (*npp1) -> ncall)
>   return 1;
> -if ( calldiff < 0 )
> - return -1;
>  return( strcmp( (*npp1) -> name , (*npp2) -> name ) );
>  }
>  
> @@ -233,26 +231,37 @@ printgprof(nltype **timesortnlp)
>   *   all else being equal, sort by names.
>   */
>  int
> -totalcmp(nltype **npp1, nltype **npp2)
> +totalcmp(const void *v1, const void *v2)
>  {
> -nltype   *np1 = *npp1;
> -nltype   

Re: [PATCH 1/2] flex 2.5.39

2015-11-20 Thread Serguey Parkhomovsky
On Thu, Nov 19, 2015 at 06:53:45PM -0500, Ted Unangst wrote:
> Serguey Parkhomovsky wrote:
> > * renamed parse.c, parse.h, scan.c, skel.c with init prefix so compiling
> >   flex outside of obj by accident wouldn't clobber the bootstrap files
> 
> Do you remember what caused you to skip using the in base yacc? The diff below
> seems to work for me.
> 

I skipped using the base yacc because flex would error out on compiling
itself. I'm not sure what was happening there, but I've tested your
patch and it works for me too.



[patch] fortune(6): fix missing negative in manpage

2015-11-19 Thread Serguey Parkhomovsky
If you are willing to be offended, then quit using -o? It should be the
opposite.

Index: fortune.6
===
RCS file: /cvs/src/games/fortune/fortune/fortune.6,v
retrieving revision 1.14
diff -u -p -r1.14 fortune.6
--- fortune.6   25 Sep 2015 17:37:23 -  1.14
+++ fortune.6   19 Nov 2015 15:46:46 -
@@ -86,7 +86,7 @@ Choose only from potentially offensive a
 Please, please, please request a potentially offensive fortune if and
 only if you believe, deep down in your heart, that you are willing
 to be offended.
-(And that if you are, you'll just quit using
+(And that if you aren't, you'll just quit using
 .Fl o
 rather than give us
 grief about it, okay?)



Re: [patch] gprof(1): fix incompatible pointer types

2015-11-16 Thread Serguey Parkhomovsky
Hi Philip,

Thanks for the detailed explanation on comparison functions for qsort. I
have looked through your changes, and have only found one issue:

> 2) totalcmp(A,B) and totalcmp(B,A) both return <0 if both A and B have 
>name==0 and cycleno!=0, and they both return >0 if both A and B have 
>naem==0 and cycleno==0, violating the consistency requirement.

The logic is still not quite right with totalcmp; it is still
inconsistent where both A and B have:
* name == 0 && cycleno == 0 (both return -1)
* name != 0 && cycleno == 0 (both return -1)
* name != 0 && cycleno != 0 (both return -1)

As well, if name == 0 && cycleno != 0, the code will drop through and
there will be a null pointer dereference:

if ( *(np1 -> name) != '_' && *(np2 -> name) == '_' )
return -1;
if ( *(np1 -> name) == '_' && *(np2 -> name) != '_' )
return 1;

What do you think of the following diff? I've put some of the boolean logic
into variables to enhance readability.

Index: arcs.c
===
RCS file: /cvs/src/usr.bin/gprof/arcs.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 arcs.c
--- arcs.c  20 Aug 2015 22:32:41 -  1.13
+++ arcs.c  16 Nov 2015 17:41:55 -
@@ -95,9 +95,14 @@ addarc(nltype *parentp, nltype *childp, 
 nltype **topsortnlp;
 
 int
-topcmp(nltype **npp1, nltype **npp2)
+topcmp(const void *v1, const void *v2)
 {
-return (*npp1) -> toporder - (*npp2) -> toporder;
+const nltype * const *npp1 = v1;
+const nltype * const *npp2 = v2;
+
+if ((*npp1) -> toporder < (*npp2) -> toporder)
+   return -1;
+return (*npp1) -> toporder > (*npp2) -> toporder;
 }
 
 nltype **
Index: gprof.h
===
RCS file: /cvs/src/usr.bin/gprof/gprof.h,v
retrieving revision 1.14
diff -u -p -u -r1.14 gprof.h
--- gprof.h 19 Oct 2013 13:51:40 -  1.14
+++ gprof.h 16 Nov 2015 17:41:55 -
@@ -281,10 +281,10 @@ void  sortchildren(nltype *);
 void   sortmembers(nltype *);
 void   sortparents(nltype *);
 void   tally(struct rawarc *);
-inttimecmp(nltype **, nltype **);
+inttimecmp(const void *, const void *);
 void   timepropagate(nltype *);
-inttopcmp(nltype **, nltype **);
-inttotalcmp(nltype **, nltype **);
+inttopcmp(const void *, const void *);
+inttotalcmp(const void *, const void *);
 
 #defineLESSTHAN-1
 #defineEQUALTO 0
Index: printgprof.c
===
RCS file: /cvs/src/usr.bin/gprof/printgprof.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 printgprof.c
--- printgprof.c20 Aug 2015 22:32:41 -  1.13
+++ printgprof.c16 Nov 2015 17:41:55 -
@@ -35,7 +35,7 @@
 #include "gprof.h"
 #include "pathnames.h"
 
-int namecmp(nltype **, nltype **);
+int namecmp(const void *, const void *);
 
 void
 printprof()
@@ -66,21 +66,19 @@ printprof()
 }
 
 int
-timecmp(nltype **npp1, nltype **npp2)
+timecmp(const void *v1, const void *v2)
 {
-double timediff;
-long   calldiff;
+const nltype * const *npp1 = v1;
+const nltype * const *npp2 = v2;
 
-timediff = (*npp2) -> time - (*npp1) -> time;
-if ( timediff > 0.0 )
+if ((*npp2) -> time < (*npp1) -> time)
+   return -1;
+if ((*npp2) -> time > (*npp1) -> time)
return 1 ;
-if ( timediff < 0.0 )
+if ((*npp2) -> ncall < (*npp1) -> ncall)
return -1;
-calldiff = (*npp2) -> ncall - (*npp1) -> ncall;
-if ( calldiff > 0 )
+if ((*npp2) -> ncall > (*npp1) -> ncall)
return 1;
-if ( calldiff < 0 )
-   return -1;
 return( strcmp( (*npp1) -> name , (*npp2) -> name ) );
 }
 
@@ -233,26 +231,37 @@ printgprof(nltype **timesortnlp)
  * all else being equal, sort by names.
  */
 int
-totalcmp(nltype **npp1, nltype **npp2)
+totalcmp(const void *v1, const void *v2)
 {
-nltype *np1 = *npp1;
-nltype *np2 = *npp2;
-double diff;
-
-diff =( np1 -> propself + np1 -> propchild )
-   - ( np2 -> propself + np2 -> propchild );
-if ( diff < 0.0 )
+const nltype *np1 = *(const nltype **)v1;
+const nltype *np2 = *(const nltype **)v2;
+double t1, t2;
+int np1noname, np2noname, np1cyclehdr, np2cyclehdr;
+
+t1 = np1 -> propself + np1 -> propchild;
+t2 = np2 -> propself + np2 -> propchild;
+if ( t2 > t1 )
return 1;
-if ( diff > 0.0 )
+if ( t2 < t1 )
return -1;
-if ( np1 -> name == 0 && np1 -> cycleno != 0 ) 
+
+np1noname = ( np1 -> name == 0 );
+np2noname = ( np2 -> name == 0 );
+np1cyclehdr = ( np1noname && np1 -> cycleno != 0 );
+np2cyclehdr = ( np2noname && np2 -> cycleno != 0 );
+
+if ( np1cyclehdr && !np2cyclehdr )
return -1;
-if ( np2 -> name == 0 && np

[patch] gprof(1): fix incompatible pointer types

2015-11-10 Thread Serguey Parkhomovsky
Hi tech@,

Some of the comparator functions in gprof(1) have incompatible pointer
types and generate compiler warnings. The following diff fixes the
problem. 

Thanks,
Serguey

Index: arcs.c
===
RCS file: /cvs/src/usr.bin/gprof/arcs.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 arcs.c
--- arcs.c  20 Aug 2015 22:32:41 -  1.13
+++ arcs.c  10 Nov 2015 18:41:38 -
@@ -95,8 +95,11 @@ addarc(nltype *parentp, nltype *childp, 
 nltype **topsortnlp;
 
 int
-topcmp(nltype **npp1, nltype **npp2)
+topcmp(const void *v1, const void *v2)
 {
+const nltype **npp1 = (const nltype **)v1;
+const nltype **npp2 = (const nltype **)v2;
+
 return (*npp1) -> toporder - (*npp2) -> toporder;
 }
 
Index: gprof.h
===
RCS file: /cvs/src/usr.bin/gprof/gprof.h,v
retrieving revision 1.14
diff -u -p -u -r1.14 gprof.h
--- gprof.h 19 Oct 2013 13:51:40 -  1.14
+++ gprof.h 10 Nov 2015 18:41:38 -
@@ -281,10 +281,10 @@ void  sortchildren(nltype *);
 void   sortmembers(nltype *);
 void   sortparents(nltype *);
 void   tally(struct rawarc *);
-inttimecmp(nltype **, nltype **);
+inttimecmp(const void *, const void *);
 void   timepropagate(nltype *);
-inttopcmp(nltype **, nltype **);
-inttotalcmp(nltype **, nltype **);
+inttopcmp(const void *, const void *);
+inttotalcmp(const void *, const void *);
 
 #defineLESSTHAN-1
 #defineEQUALTO 0
Index: printgprof.c
===
RCS file: /cvs/src/usr.bin/gprof/printgprof.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 printgprof.c
--- printgprof.c20 Aug 2015 22:32:41 -  1.13
+++ printgprof.c10 Nov 2015 18:41:39 -
@@ -35,7 +35,7 @@
 #include "gprof.h"
 #include "pathnames.h"
 
-int namecmp(nltype **, nltype **);
+int namecmp(const void *, const void *);
 
 void
 printprof()
@@ -66,8 +66,10 @@ printprof()
 }
 
 int
-timecmp(nltype **npp1, nltype **npp2)
+timecmp(const void *v1, const void *v2)
 {
+const nltype **npp1 = (const nltype **)v1;
+const nltype **npp2 = (const nltype **)v2;
 double timediff;
 long   calldiff;
 
@@ -233,10 +235,10 @@ printgprof(nltype **timesortnlp)
  * all else being equal, sort by names.
  */
 int
-totalcmp(nltype **npp1, nltype **npp2)
+totalcmp(const void *v1, const void *v2)
 {
-nltype *np1 = *npp1;
-nltype *np2 = *npp2;
+const nltype *np1 = *(const nltype **)v1;
+const nltype *np2 = *(const nltype **)v2;
 double diff;
 
 diff =( np1 -> propself + np1 -> propchild )
@@ -642,8 +644,11 @@ printblurb(const char *blurbname)
 }
 
 int
-namecmp(nltype **npp1, nltype **npp2)
+namecmp(const void *v1, const void *v2)
 {
+const nltype **npp1 = (const nltype **)v1;
+const nltype **npp2 = (const nltype **)v2;
+
 return( strcmp( (*npp1) -> name , (*npp2) -> name ) );
 }
 



[PATCH 2/2] flex 2.5.39

2015-11-07 Thread Serguey Parkhomovsky
This patch includes minor changes to files that wouldn't compile with flex
2.5.39.

Index: usr.sbin/config/scan.l
===
RCS file: /cvs/src/usr.sbin/config/scan.l,v
retrieving revision 1.22
diff -u -p -u -r1.22 scan.l
--- usr.sbin/config/scan.l  16 Jan 2015 06:40:16 -  1.22
+++ usr.sbin/config/scan.l  7 Nov 2015 05:26:23 -
@@ -67,9 +67,9 @@ struct incl {
 static struct incl *incl;
 static int endinclude(void);
 
-#defineyywrap() 1
-
 %}
+
+%option noyywrap
 
 PATH   [A-Za-z_0-9]*[./][-A-Za-z_0-9./\$\{\}]*
 WORD   [A-Za-z_][-A-Za-z_0-9]*
Index: lib/libkeynote/keynote.l
===
RCS file: /cvs/src/lib/libkeynote/keynote.l,v
retrieving revision 1.21
diff -u -p -u -r1.21 keynote.l
--- lib/libkeynote/keynote.l4 Feb 2015 20:35:51 -   1.21
+++ lib/libkeynote/keynote.l7 Nov 2015 05:26:23 -
@@ -746,7 +746,6 @@ keynote_get_envlist(char *buf, char *buf
 if (0)
 {
yyunput(0, NULL);
-   yy_flex_realloc(0, 0);
 }
 
 return en;
Index: lib/libkeynote/keynote-ver.l
===
RCS file: /cvs/src/lib/libkeynote/keynote-ver.l,v
retrieving revision 1.16
diff -u -p -u -r1.16 keynote-ver.l
--- lib/libkeynote/keynote-ver.l29 Nov 2013 19:00:51 -  1.16
+++ lib/libkeynote/keynote-ver.l7 Nov 2015 05:26:23 -
@@ -252,7 +252,6 @@ read_environment(char *filename)
 if (0)
 {
yyunput(0, NULL);
-   yy_flex_realloc(0, 0);
 }
 }
 
Index: sbin/wsconsctl/map_scan.l
===
RCS file: /cvs/src/sbin/wsconsctl/map_scan.l,v
retrieving revision 1.5
diff -u -p -u -r1.5 map_scan.l
--- sbin/wsconsctl/map_scan.l   18 Apr 2015 18:28:37 -  1.5
+++ sbin/wsconsctl/map_scan.l   7 Nov 2015 05:26:23 -
@@ -30,6 +30,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+%option noyywrap
+
 %{
 
 #include 
@@ -38,8 +40,6 @@
 #include 
 #include "wsconsctl.h"
 #include "y.tab.h"
-
-#define yywrap()   1
 
 void
 map_scan_setinput(char *str)



Upgrading flex?

2015-10-31 Thread Serguey Parkhomovsky
Hi tech@,

Is there any interest in having a newer version of flex in base? I
recently tried compiling some software with OpenBSD's flex, but had to
tweak some code in order to get it to compile with 2.5.4. Of course, I
could always install the flex in ports to get a newer version, but I was
wondering what would be involved/if anyone is working on this already.

Thanks,
Serguey