session leakage in httpd

2015-08-09 Thread Arto Jonsson
Hi,

while testing the -current (I also see the issue on 5.7) httpd with a
fuzzer I noticed that some HTTP requests result in the session not
closing properly.

I've attached inline a Python script that should demostrate the issue.
I've tested the issue locally and from adjacent network.

After running the Python script against httpd for a couple of times you
should see the following in `fstat'.

$ fstat | grep '^www'
* snip*
www  httpd  268603* internet stream tcp 0x0 *:80
www  httpd  268604* unix stream 0x0
www  httpd  268605* internet stream tcp 0x0 *:0
www  httpd  268606* internet stream tcp 0x0 *:0
www  httpd  268607* unix stream 0x0
www  httpd  268608* internet stream tcp 0x0 *:0
www  httpd  268609 kqueue 0x0 0 state: W
www  httpd  26860   10* internet stream tcp 0x0 *:0
www  httpd  26860   11* internet stream tcp 0x0 *:0
www  httpd  26860   12* internet stream tcp 0x0 *:0
www  httpd  26860   13* internet stream tcp 0x0 *:0
www  httpd  26860   14* internet stream tcp 0x0 *:0
www  httpd  26860   15* internet stream tcp 0x0 *:0

Note the sockets #10-#15.

Normally I would provide a patch when reporting issues but I've been
trying to debug this for a while and I thought reporting this now
would make it possible to get it fixed before release.

---8

Re: print time_t with %lld in last(1)

2014-04-15 Thread Arto Jonsson
ping

On Sun, Mar 23, 2014 at 07:31:11PM +0200, Arto Jonsson wrote:
> Index: last.c
> ===
> RCS file: /cvs/src/usr.bin/last/last.c,v
> retrieving revision 1.39
> diff -u -p -r1.39 last.c
> --- last.c22 Aug 2013 04:43:40 -  1.39
> +++ last.c27 Feb 2014 13:55:22 -
> @@ -266,8 +266,8 @@ wtmp(void)
>*/
>   if (want(bp, NO)) {
>   if (seconds) {
> - snprintf(tim, sizeof tim, "%ld",
> - (long)bp->ut_time);
> + snprintf(tim, sizeof tim, 
> "%lld",
> + (long long)bp->ut_time);
>   } else {
>   ct = ctime(&bp->ut_time);
>   snprintf(tim, sizeof tim,
> @@ -296,8 +296,8 @@ wtmp(void)
>   !bp->ut_line[1]) {
>   if (want(bp, NO)) {
>   if (seconds) {
> - snprintf(tim, sizeof tim, "%ld",
> - (long)bp->ut_time);
> + snprintf(tim, sizeof tim, 
> "%lld",
> + (long long)bp->ut_time);
>   } else {
>   ct = ctime(&bp->ut_time);
>   snprintf(tim, sizeof tim,
> @@ -339,8 +339,8 @@ wtmp(void)
>   T->logout < 0 {
>   snapfound = 1;
>   if (seconds) {
> - snprintf(tim, sizeof tim, "%ld",
> - (long)bp->ut_time);
> + snprintf(tim, sizeof tim, "%lld",
> + (long long)bp->ut_time);
>   } else {
>   ct = ctime(&bp->ut_time);
>   snprintf(tim, sizeof tim,
> @@ -361,8 +361,8 @@ wtmp(void)
>   printf("- %s", crmsg);
>   } else {
>   if (seconds)
> - printf("- %ld",
> - (long)T->logout);
> + printf("- %lld",
> + (long 
> long)T->logout);
>   else
>   printf("- %*.*s",
>   timesize, timesize,
> @@ -370,7 +370,7 @@ wtmp(void)
>   }
>   delta = T->logout - bp->ut_time;
>   if (seconds)
> - printf("  (%ld)\n", 
> (long)delta);
> + printf("  (%lld)\n", (long 
> long)delta);
>   else {
>   if (delta < SECSPERDAY)
>   printf("  (%*.*s)\n",



security(8): check for nobody in /etc/ftpusers

2014-03-23 Thread Arto Jonsson
Or should this check removed completely?

Index: security
===
RCS file: /cvs/src/libexec/security/security,v
retrieving revision 1.23
diff -u -p -r1.23 security
--- security21 Mar 2013 09:37:37 -  1.23
+++ security23 Mar 2014 18:07:11 -
@@ -287,11 +287,11 @@ sub check_ksh {
}
 }
 
-# Root and uucp should both be in /etc/ftpusers.
+# nobody should be in /etc/ftpusers.
 sub check_ftpusers {
my $filename = '/etc/ftpusers';
nag !(open my $fh, '<', $filename), "open: $filename: $!" and return;
-   my %banned = qw(root 1 uucp 1);
+   my %banned = qw(nobody 1);
while (<$fh>) {
chomp;
delete $banned{$_};



print time_t with %lld in last(1)

2014-03-23 Thread Arto Jonsson
Index: last.c
===
RCS file: /cvs/src/usr.bin/last/last.c,v
retrieving revision 1.39
diff -u -p -r1.39 last.c
--- last.c  22 Aug 2013 04:43:40 -  1.39
+++ last.c  27 Feb 2014 13:55:22 -
@@ -266,8 +266,8 @@ wtmp(void)
 */
if (want(bp, NO)) {
if (seconds) {
-   snprintf(tim, sizeof tim, "%ld",
-   (long)bp->ut_time);
+   snprintf(tim, sizeof tim, 
"%lld",
+   (long long)bp->ut_time);
} else {
ct = ctime(&bp->ut_time);
snprintf(tim, sizeof tim,
@@ -296,8 +296,8 @@ wtmp(void)
!bp->ut_line[1]) {
if (want(bp, NO)) {
if (seconds) {
-   snprintf(tim, sizeof tim, "%ld",
-   (long)bp->ut_time);
+   snprintf(tim, sizeof tim, 
"%lld",
+   (long long)bp->ut_time);
} else {
ct = ctime(&bp->ut_time);
snprintf(tim, sizeof tim,
@@ -339,8 +339,8 @@ wtmp(void)
T->logout < 0 {
snapfound = 1;
if (seconds) {
-   snprintf(tim, sizeof tim, "%ld",
-   (long)bp->ut_time);
+   snprintf(tim, sizeof tim, "%lld",
+   (long long)bp->ut_time);
} else {
ct = ctime(&bp->ut_time);
snprintf(tim, sizeof tim,
@@ -361,8 +361,8 @@ wtmp(void)
printf("- %s", crmsg);
} else {
if (seconds)
-   printf("- %ld",
-   (long)T->logout);
+   printf("- %lld",
+   (long 
long)T->logout);
else
printf("- %*.*s",
timesize, timesize,
@@ -370,7 +370,7 @@ wtmp(void)
}
delta = T->logout - bp->ut_time;
if (seconds)
-   printf("  (%ld)\n", 
(long)delta);
+   printf("  (%lld)\n", (long 
long)delta);
else {
if (delta < SECSPERDAY)
printf("  (%*.*s)\n",



fix ntpd.8 rfc authors

2014-02-12 Thread Arto Jonsson
University of Delaware mixup.

Index: ntpd.8
===
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.8,v
retrieving revision 1.36
diff -u -p -r1.36 ntpd.8
--- ntpd.8  4 Oct 2013 14:28:16 -   1.36
+++ ntpd.8  12 Feb 2014 14:37:13 -
@@ -153,7 +153,6 @@ Socket file for communication with
 .Pp
 .Rs
 .%A D. Mills
-.%A U. Delaware
 .%A J. Martin
 .%A J. Burbank
 .%A W. Kasch



Use explicit_bzero in login_*

2014-02-05 Thread Arto Jonsson
Index: login_chpass/login_chpass.c
===
RCS file: /cvs/src/libexec/login_chpass/login_chpass.c,v
retrieving revision 1.16
diff -u -p -r1.16 login_chpass.c
--- login_chpass/login_chpass.c 4 Dec 2012 02:24:47 -   1.16
+++ login_chpass/login_chpass.c 5 Feb 2014 15:44:26 -
@@ -208,7 +208,7 @@ yp_chpass(char *username)
pwd_gensalt(salt, sizeof(salt), lc, 'y') == 0)
strlcpy(salt, "xx", sizeof(salt));
crypt(p, salt);
-   memset(p, 0, strlen(p));
+   explicit_bzero(p, strlen(p));
}
warnx("YP passwd database unchanged.");
exit(1);
Index: login_lchpass/login_lchpass.c
===
RCS file: /cvs/src/libexec/login_lchpass/login_lchpass.c,v
retrieving revision 1.14
diff -u -p -r1.14 login_lchpass.c
--- login_lchpass/login_lchpass.c   4 Dec 2012 02:24:47 -   1.14
+++ login_lchpass/login_lchpass.c   5 Feb 2014 15:44:27 -
@@ -136,7 +136,7 @@ main(int argc, char *argv[])
exit(1);
 
salt = crypt(p, salt);
-   memset(p, 0, strlen(p));
+   explicit_bzero(p, strlen(p));
if (!pwd || strcmp(salt, pwd->pw_passwd) != 0)
exit(1);
 
Index: login_passwd/login.c
===
RCS file: /cvs/src/libexec/login_passwd/login.c,v
retrieving revision 1.10
diff -u -p -r1.10 login.c
--- login_passwd/login.c1 Jun 2012 01:43:19 -   1.10
+++ login_passwd/login.c5 Feb 2014 15:44:27 -
@@ -158,7 +158,7 @@ main(int argc, char **argv)
 #endif
 
if (password != NULL)
-   memset(password, 0, strlen(password));
+   explicit_bzero(password, strlen(password));
if (ret != AUTH_OK)
fprintf(back, BI_REJECT "\n");
 
Index: login_passwd/login_passwd.c
===
RCS file: /cvs/src/libexec/login_passwd/login_passwd.c,v
retrieving revision 1.9
diff -u -p -r1.9 login_passwd.c
--- login_passwd/login_passwd.c 9 Mar 2006 19:14:10 -   1.9
+++ login_passwd/login_passwd.c 5 Feb 2014 15:44:27 -
@@ -62,7 +62,7 @@ pwd_login(char *username, char *password
 
salt = crypt(password, salt);
plen = strlen(password);
-   memset(password, 0, plen);
+   explicit_bzero(password, plen);
 
/*
 * Authentication fails if the user does not exist in the password
Index: login_tis/login_tis.c
===
RCS file: /cvs/src/libexec/login_tis/login_tis.c,v
retrieving revision 1.11
diff -u -p -r1.11 login_tis.c
--- login_tis/login_tis.c   4 Dec 2012 02:24:47 -   1.11
+++ login_tis/login_tis.c   5 Feb 2014 15:44:27 -
@@ -394,8 +394,8 @@ tis_getkey(struct tis_connection *tc)
}
DES_string_to_key(key, &cblock);
error = DES_set_key(&cblock, &tc->keysched);
-   memset(key, 0, len);
-   memset(&cblock, 0, sizeof(cblock));
+   explicit_bzero(key, len);
+   explicit_bzero(&cblock, sizeof(cblock));
free(tbuf);
return (error);
 }
@@ -507,10 +507,10 @@ tis_recv(struct tis_connection *tc, u_ch
len, &ks, &iv, DES_DECRYPT);
if (strlcpy(buf, tbuf, bufsiz) >= bufsiz) {
syslog(LOG_ERR, "unencrypted data too large to store");
-   memset(tbuf, 0, sizeof(tbuf));
+   explicit_bzero(tbuf, sizeof(tbuf));
return (-1);
}
-   memset(tbuf, 0, sizeof(tbuf));
+   explicit_bzero(tbuf, sizeof(tbuf));
}
return (len);
 }
@@ -656,7 +656,7 @@ tis_authorize(struct tis_connection *tc,
syslog(LOG_ERR, "unexpected response from authsrv: %s", obuf);
resp = error;
}
-   memset(buf, 0, sizeof(buf));
+   explicit_bzero(buf, sizeof(buf));
 
return (resp);
 }
@@ -684,10 +684,10 @@ tis_verify(struct tis_connection *tc, co
if (strncmp(buf, "ok", 2) == 0) {
if (buf[2] != '\0')
strlcpy(ebuf, buf + 3, TIS_BUFSIZ);
-   memset(buf, 0, sizeof(buf));
+   explicit_bzero(buf, sizeof(buf));
return (0);
}
strlcpy(ebuf, buf, TIS_BUFSIZ);
-   memset(buf, 0, sizeof(buf));
+   explicit_bzero(buf, sizeof(buf));
return (-1);
 }
Index: login_yubikey/login_yubikey.c
===
RCS file: /cvs/src/libexec/login_yubikey/login_yubikey.c,v
retrieving revision 1.8
diff -u -p -r1.8 login_yubikey.c
--- login_yubikey/login_yubikey.c   27 Nov 2013 21:25:25 -  1.8
+++ login_yubikey/login_yubikey.c   5 Feb

Re: new queue support for systat(1)

2013-11-26 Thread Arto Jonsson
On Thu, Nov 21, 2013 at 12:35:43PM +0200, Arto Jonsson wrote:
> Hi,
> 
> the following adds new queue support for systat(1). Both old and new
> queues are shown in the same display (newqs are shown first). Majority
> of the code taken from pfctl.
> 
> For new queues the BW field only shows the target bandwidth (no burst
> info for example).

ping



new queue support for systat(1)

2013-11-21 Thread Arto Jonsson
Hi,

the following adds new queue support for systat(1). Both old and new
queues are shown in the same display (newqs are shown first). Majority
of the code taken from pfctl.

For new queues the BW field only shows the target bandwidth (no burst
info for example).

Index: pftop.c
===
RCS file: /cvs/src/usr.bin/systat/pftop.c,v
retrieving revision 1.21
diff -u -p -r1.21 pftop.c
--- pftop.c 12 Oct 2013 12:17:32 -  1.21
+++ pftop.c 21 Nov 2013 10:23:10 -
@@ -46,6 +46,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -115,6 +117,7 @@ u_int32_t num_states = 0;
 u_int32_t num_states_all = 0;
 u_int32_t num_rules = 0;
 u_int32_t num_queues = 0;
+u_int32_t num_altqs = 0;
 int cachestates = 0;
 
 char *filter_string = NULL;
@@ -303,7 +306,7 @@ union class_stats {
struct hfsc_classstats  hfsc_stats;
 };
 
-struct queue_stats {
+struct altq_stats {
union class_statsdata;
struct timeval   timestamp;
u_int8_t valid;
@@ -314,12 +317,28 @@ struct pf_altq_node {
struct pf_altq_node *next;
struct pf_altq_node *children;
struct pf_altq_node *next_flat;
-   struct queue_stats   qstats;
-   struct queue_stats   qstats_last;
+   struct altq_statsqstats;
+   struct altq_statsqstats_last;
u_int8_t depth;
u_int8_t visited;
 };
 
+/* queue structures from pfctl */
+
+struct queue_stats {
+   struct hfsc_class_stats  data;
+   int  valid;
+   struct timeval   timestamp;
+};
+
+struct pfctl_queue_node {
+   TAILQ_ENTRY(pfctl_queue_node)   entries;
+   struct pf_queuespec qs;
+   struct queue_stats  qstats;
+   struct queue_stats  qstats_last;
+   int depth;
+};
+TAILQ_HEAD(qnodes, pfctl_queue_node) qnodes = TAILQ_HEAD_INITIALIZER(qnodes);
 
 /* ordering functions */
 
@@ -1515,7 +1534,7 @@ pfctl_find_altq_node(struct pf_altq_node
 
 void
 pfctl_insert_altq_node(struct pf_altq_node **root,
-const struct pf_altq altq, const struct queue_stats qstats)
+const struct pf_altq altq, const struct altq_stats qstats)
 {
struct pf_altq_node *node;
 
@@ -1569,14 +1588,106 @@ pfctl_set_next_flat(struct pf_altq_node 
}
 }
 
+struct pfctl_queue_node *
+pfctl_find_queue_node(const char *qname, const char *ifname)
+{
+   struct pfctl_queue_node *node;
+
+   TAILQ_FOREACH(node, &qnodes, entries)
+   if (!strcmp(node->qs.qname, qname)
+   && !(strcmp(node->qs.ifname, ifname)))
+   return (node);
+   return (NULL);
+}
+
+void
+pfctl_insert_queue_node(const struct pf_queuespec qs,
+const struct queue_stats qstats)
+{
+   struct pfctl_queue_node *node, *parent;
+
+   node = calloc(1, sizeof(struct pfctl_queue_node));
+   if (node == NULL)
+   err(1, "pfctl_insert_queue_node: calloc");
+   memcpy(&node->qs, &qs, sizeof(qs));
+   memcpy(&node->qstats, &qstats, sizeof(qstats));
+
+   if (node->qs.parent[0]) {
+   parent = pfctl_find_queue_node(node->qs.parent,
+   node->qs.ifname);
+   if (parent)
+   node->depth = parent->depth + 1;
+   }
+
+   TAILQ_INSERT_TAIL(&qnodes, node, entries);
+}
+
+int
+pfctl_update_qstats(void)
+{
+   struct pfctl_queue_node *node;
+   struct pfioc_queue   pq;
+   struct pfioc_qstats  pqs;
+   u_int32_tmnr, nr;
+   struct queue_stats   qstats;
+   static u_int32_t last_ticket;
+
+   memset(&pq, 0, sizeof(pq));
+   memset(&pqs, 0, sizeof(pqs));
+   memset(&qstats, 0, sizeof(qstats));
+
+   if (pf_dev < 0)
+   return (-1);
+
+   if (ioctl(pf_dev, DIOCGETQUEUES, &pq)) {
+   error("DIOCGETQUEUES: %s", strerror(errno));
+   return (-1);
+   }
+
+   /* if a new set is found, start over */
+   if (pq.ticket != last_ticket)
+   while ((node = TAILQ_FIRST(&qnodes)) != NULL)
+   TAILQ_REMOVE(&qnodes, node, entries);
+   last_ticket = pq.ticket;
+
+   num_queues = mnr = pq.nr;
+   for (nr = 0; nr < mnr; ++nr) {
+   pqs.nr = nr;
+   pqs.ticket = pq.ticket;
+   pqs.buf = &qstats.data;
+   pqs.nbytes = sizeof(qstats.data);
+   if (ioctl(pf_dev, DIOCGETQSTATS, &pqs)) {
+   error("DIOCGETQSTATS: %s", strerror(errno));
+   return (-1);
+   }
+   if (pqs.queue.qname[0] != '_') {
+   if (pqs.queue.parent[0] && pqs.queue.parent[0] == '_')
+   pqs.queue.parent[0] = '\0';
+   qstats.v

Re: remove some altq references from manuals

2013-11-01 Thread Arto Jonsson
On Fri, Nov 01, 2013 at 10:45:16AM +, Stuart Henderson wrote:
> On 2013/10/31 21:06, Arto Jonsson wrote:
> > Index: usr.bin/systat/systat.1
> > ===
> > RCS file: /cvs/src/usr.bin/systat/systat.1,v
> > retrieving revision 1.96
> > diff -u -p -r1.96 systat.1
> > --- usr.bin/systat/systat.1 7 Sep 2013 11:43:50 -   1.96
> > +++ usr.bin/systat/systat.1 19 Oct 2013 16:34:56 -
> > @@ -376,9 +376,8 @@ Available orderings are:
> >  and
> >  .Ic number of pages .
> >  .It Ic queues
> > -Display statistics about the active
> > -.Xr altq 9
> > -queues, similar to the output of
> > +Display statistics about the active queues,
> > +similar to the output of
> >  .Cm pfctl Fl s Cm queue .
> >  .It Ic rules
> >  Display pf rules statistics, similar to the output of
> > 
> 
> Actually this one is incorrect. systat only handles altq queues.

I guess I just volunteered myself to add those bits to systat.



remove some altq references from manuals

2013-10-31 Thread Arto Jonsson
Index: sbin/iked/iked.conf.5
===
RCS file: /cvs/src/sbin/iked/iked.conf.5,v
retrieving revision 1.25
diff -u -p -r1.25 iked.conf.5
--- sbin/iked/iked.conf.5   16 Jul 2013 09:45:28 -  1.25
+++ sbin/iked/iked.conf.5   19 Oct 2013 16:34:48 -
@@ -624,17 +624,16 @@ The following
 fragment uses queues for all IPsec traffic with special
 handling for developers and employees:
 .Bd -literal -offset indent
-altq on ix0 cbq bandwidth 1000Mb \e
-   queue { deflt, developers, employees, ipsec }
-queue deflt bandwidth 10% priority 0 cbq(default ecn)
-queue developers bandwidth 75% priority 7 cbq(borrow red)
-queue employees bandwidth 5% cbq(red)
-queue ipsec bandwidth 10% cbq(red)
+queue std on ix0 bandwidth 100M
+queue   deflt parent std bandwidth 10M default
+queue   developers parent std bandwidth 75M
+queue   employees parent std bandwidth 5M
+queue   ipsec parent std bandwidth 10M
 
-pass out on ix0 proto esp queue ipsec
+pass out on ix0 proto esp set queue ipsec
 
-pass out on ix0 tagged ipsec-developers.example.com queue developers
-pass out on ix0 tagged ipsec-employees.example.com queue employees
+pass out on ix0 tagged ipsec-developers.example.com set queue developers
+pass out on ix0 tagged ipsec-employees.example.com set queue employees
 .Ed
 .Pp
 The following example assigns the tags in the
Index: sbin/ipsecctl/ipsec.conf.5
===
RCS file: /cvs/src/sbin/ipsecctl/ipsec.conf.5,v
retrieving revision 1.143
diff -u -p -r1.143 ipsec.conf.5
--- sbin/ipsecctl/ipsec.conf.5  29 Jun 2013 09:08:41 -  1.143
+++ sbin/ipsecctl/ipsec.conf.5  19 Oct 2013 16:34:48 -
@@ -544,17 +544,16 @@ The following
 fragment uses queues for all IPsec traffic with special
 handling for developers and employees:
 .Bd -literal -offset indent
-altq on sk0 cbq bandwidth 1000Mb \e
-   queue { deflt, developers, employees, ipsec }
-queue deflt bandwidth 10% priority 0 cbq(default ecn)
-queue developers bandwidth 75% priority 7 cbq(borrow red)
-queue employees bandwidth 5% cbq(red)
-queue ipsec bandwidth 10% cbq(red)
+queue std on sk0 bandwidth 100M
+queue   deflt parent std bandwidth 10M default
+queue   developers parent std bandwidth 75M
+queue   employees parent std bandwidth 5M
+queue   ipsec parent std bandwidth 10M
 
-pass out on sk0 proto esp queue ipsec
+pass out on sk0 proto esp set queue ipsec
 
-pass out on sk0 tagged ipsec-developers.bar.org queue developers
-pass out on sk0 tagged ipsec-employees.bar.org queue employees
+pass out on sk0 tagged ipsec-developers.bar.org set queue developers
+pass out on sk0 tagged ipsec-employees.bar.org set queue employees
 .Ed
 .Pp
 The tags will be assigned by the following
Index: usr.bin/systat/systat.1
===
RCS file: /cvs/src/usr.bin/systat/systat.1,v
retrieving revision 1.96
diff -u -p -r1.96 systat.1
--- usr.bin/systat/systat.1 7 Sep 2013 11:43:50 -   1.96
+++ usr.bin/systat/systat.1 19 Oct 2013 16:34:56 -
@@ -376,9 +376,8 @@ Available orderings are:
 and
 .Ic number of pages .
 .It Ic queues
-Display statistics about the active
-.Xr altq 9
-queues, similar to the output of
+Display statistics about the active queues,
+similar to the output of
 .Cm pfctl Fl s Cm queue .
 .It Ic rules
 Display pf rules statistics, similar to the output of



fix typo in ltrace usage

2013-06-05 Thread Arto Jonsson
Index: ktrace.c
===
RCS file: /cvs/src/usr.bin/ktrace/ktrace.c,v
retrieving revision 1.25
diff -u -r1.25 ktrace.c
--- ktrace.c1 Jun 2013 09:57:58 -   1.25
+++ ktrace.c5 Jun 2013 07:55:58 -
@@ -215,7 +215,7 @@
 {
if (is_ltrace)
fprintf(stderr, "usage: %s [-ai] [-f trfile] [-u trspec]"
-   "  comand\n",
+   "  command\n",
__progname);
else
fprintf(stderr, "usage: %s [-aBCcdi] [-f trfile] [-g pgid]"



Re: add nl(1)

2013-05-28 Thread Arto Jonsson
ping

> Updated diff. I removed the int width handling and modified the
> separator printing based on your comment.
> 
> Index: Makefile
> ===
> RCS file: /cvs/src/usr.bin/Makefile,v
> retrieving revision 1.129
> diff -u -p -r1.129 Makefile
> --- Makefile  15 Mar 2013 06:01:41 -  1.129
> +++ Makefile  20 May 2013 09:28:57 -
> @@ -16,7 +16,7 @@ SUBDIR= apply apropos ar arch asa asn1_c
>   m4 mail make man mandoc mesg mg \
>   midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
>   newsyslog \
> - nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
> + nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
>   pkg-config pkill \
>   pr printenv printf quota radioctl ranlib rcs rdist rdistd \
>   readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
> Index: nl/Makefile
> ===
> RCS file: nl/Makefile
> diff -N nl/Makefile
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ nl/Makefile   20 May 2013 09:28:57 -
> @@ -0,0 +1,6 @@
> +#$OpenBSD$
> +#$NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
> +
> +PROG=nl
> +
> +.include 
> Index: nl/nl.1
> ===
> RCS file: nl/nl.1
> diff -N nl/nl.1
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ nl/nl.1   20 May 2013 09:28:57 -
> @@ -0,0 +1,216 @@
> +.\"  $OpenBSD$
> +.\"  $NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
> +.\"
> +.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
> +.\" All rights reserved.
> +.\"
> +.\" This code is derived from software contributed to The NetBSD Foundation
> +.\" by Klaus Klein.
> +.\"
> +.\" Redistribution and use in source and binary forms, with or without
> +.\" modification, are permitted provided that the following conditions
> +.\" are met:
> +.\" 1. Redistributions of source code must retain the above copyright
> +.\"notice, this list of conditions and the following disclaimer.
> +.\" 2. Redistributions in binary form must reproduce the above copyright
> +.\"notice, this list of conditions and the following disclaimer in the
> +.\"documentation and/or other materials provided with the distribution.
> +.\"
> +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
> +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
> LIMITED
> +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
> PARTICULAR
> +.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
> +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
> THE
> +.\" POSSIBILITY OF SUCH DAMAGE.
> +.\"
> +.Dd $Mdocdate$
> +.Dt NL 1
> +.Os
> +.Sh NAME
> +.Nm nl
> +.Nd line numbering filter
> +.Sh SYNOPSIS
> +.Nm
> +.Op Fl p
> +.Op Fl b Ar type
> +.Op Fl d Ar delim
> +.Op Fl f Ar type
> +.Op Fl h Ar type
> +.Op Fl i Ar incr
> +.Op Fl l Ar num
> +.Op Fl n Ar format
> +.Op Fl s Ar sep
> +.Op Fl v Ar startnum
> +.Op Fl w Ar width
> +.Op Ar file
> +.Sh DESCRIPTION
> +The
> +.Nm
> +utility reads lines from the named
> +.Ar file ,
> +applies a configurable line numbering filter operation and writes the result
> +to the standard output.
> +If
> +.Ar file
> +is a single dash
> +.Pq Sq \&-
> +or absent,
> +.Nm
> +reads from the standard input.
> +.Pp
> +The
> +.Nm
> +utility treats the text it reads in terms of logical pages.
> +Unless specified otherwise, line numbering is reset at the start of each
> +logical page.
> +A logical page consists of a header, a body and a footer section; empty
> +sections are valid.
> +Different line numbering options are independently available for header,
> +body and footer sections.
> +.Pp
> +The starts of logical page sections are signaled by input lines containing
> +nothing but one of the following sequences of delimiter characters:
> +.Bd -unfilled -offset indent
> +.Bl -column "\e:\e:\e: " "header "
> +.It Em "Line""Start of"
> +.It \e:\e:\e:header
> +.It \e:\e:   body
> +.It \e:  footer
> +.El
> +.Ed
> +.Pp
> +If the input does not contain any logical page section signaling directives,
> +the text being read is assumed to consist of a single logical page body.
> +.Pp
> +The following options are available:
> +.Bl -tag -width indent
> +.It Fl b Ar type
> +Specify the logical page body lines to be numbered.
> +Recognized
> +.Ar type
> +arguments are:
> +.Bl -tag -width pstringXX
> +.It a
> +Number all lines.
> +

Re: add nl(1)

2013-05-20 Thread Arto Jonsson
On Wed, May 15, 2013 at 06:16:55AM -0600, Todd C. Miller wrote:
> I've taken your diff and merged some useful bits from FreeBSD.
> Specifically, the use of getline() and multibyte support for the
> -d option.
> 
> I also made the functions non-static (though I don't think that is
> such a big deal) and tweaked the manual to treat '-' like cat(1)
> as per j...@wxcvbn.org's comments.

Updated diff. I removed the int width handling and modified the
separator printing based on your comment.

Index: Makefile
===
RCS file: /cvs/src/usr.bin/Makefile,v
retrieving revision 1.129
diff -u -p -r1.129 Makefile
--- Makefile15 Mar 2013 06:01:41 -  1.129
+++ Makefile20 May 2013 09:28:57 -
@@ -16,7 +16,7 @@ SUBDIR= apply apropos ar arch asa asn1_c
m4 mail make man mandoc mesg mg \
midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
newsyslog \
-   nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
+   nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
pkg-config pkill \
pr printenv printf quota radioctl ranlib rcs rdist rdistd \
readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
Index: nl/Makefile
===
RCS file: nl/Makefile
diff -N nl/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/Makefile 20 May 2013 09:28:57 -
@@ -0,0 +1,6 @@
+#  $OpenBSD$
+#  $NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
+
+PROG=  nl
+
+.include 
Index: nl/nl.1
===
RCS file: nl/nl.1
diff -N nl/nl.1
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/nl.1 20 May 2013 09:28:57 -
@@ -0,0 +1,216 @@
+.\"$OpenBSD$
+.\"$NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Klaus Klein.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd $Mdocdate$
+.Dt NL 1
+.Os
+.Sh NAME
+.Nm nl
+.Nd line numbering filter
+.Sh SYNOPSIS
+.Nm
+.Op Fl p
+.Op Fl b Ar type
+.Op Fl d Ar delim
+.Op Fl f Ar type
+.Op Fl h Ar type
+.Op Fl i Ar incr
+.Op Fl l Ar num
+.Op Fl n Ar format
+.Op Fl s Ar sep
+.Op Fl v Ar startnum
+.Op Fl w Ar width
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads lines from the named
+.Ar file ,
+applies a configurable line numbering filter operation and writes the result
+to the standard output.
+If
+.Ar file
+is a single dash
+.Pq Sq \&-
+or absent,
+.Nm
+reads from the standard input.
+.Pp
+The
+.Nm
+utility treats the text it reads in terms of logical pages.
+Unless specified otherwise, line numbering is reset at the start of each
+logical page.
+A logical page consists of a header, a body and a footer section; empty
+sections are valid.
+Different line numbering options are independently available for header,
+body and footer sections.
+.Pp
+The starts of logical page sections are signaled by input lines containing
+nothing but one of the following sequences of delimiter characters:
+.Bd -unfilled -offset indent
+.Bl -column "\e:\e:\e: " "header "
+.It Em "Line"  "Start of"
+.It \e:\e:\e:  header
+.It \e:\e: body
+.It \e:footer
+.El
+.Ed
+.Pp
+If the input does not contain any logical page section signaling directives,
+the text being read is assumed to consist of a single logical page body.
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl b Ar type
+Specify the logical page body lines t

Re: add nl(1)

2013-05-15 Thread Arto Jonsson
On Wed, May 15, 2013 at 07:52:30AM -0600, Todd C. Miller wrote:
> If that's the case, can't we just do:
> 
> if (donumber) {
>   (void)printf(format, width, line);
>   line += incr;
>   (void)fputs(sep, stdout);
> } else {
>   (void)printf("%*s", width, "");
> }
> (void)fwrite(buffer, linelen, 1, stdout);

Yeah. I was thinking something too complex.



Re: add nl(1)

2013-05-15 Thread Arto Jonsson
On Wed, May 15, 2013 at 06:16:55AM -0600, Todd C. Miller wrote:
> I've taken your diff and merged some useful bits from FreeBSD.
> Specifically, the use of getline() and multibyte support for the
> -d option.

I asked stsp@ about the multibyte support yesterday and it was his
opinion that it's not currently needed.

Some comments inline based on what I've developed further.

> I also made the functions non-static (though I don't think that is
> such a big deal) and tweaked the manual to treat '-' like cat(1)
> as per j...@wxcvbn.org's comments.
> 
>  - todd
> 
> Index: Makefile
> ===
> RCS file: /home/cvs/openbsd/src/usr.bin/Makefile,v
> retrieving revision 1.129
> diff -u -r1.129 Makefile
> --- Makefile  15 Mar 2013 06:01:41 -  1.129
> +++ Makefile  15 May 2013 11:43:52 -
> @@ -16,7 +16,7 @@
>   m4 mail make man mandoc mesg mg \
>   midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
>   newsyslog \
> - nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
> + nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
>   pkg-config pkill \
>   pr printenv printf quota radioctl ranlib rcs rdist rdistd \
>   readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
> Index: nl/Makefile
> ===
> RCS file: nl/Makefile
> diff -N nl/Makefile
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ nl/Makefile   15 May 2013 11:43:52 -
> @@ -0,0 +1,6 @@
> +#$OpenBSD$
> +#$NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
> +
> +PROG=nl
> +
> +.include 
> Index: nl/nl.1
> ===
> RCS file: nl/nl.1
> diff -N nl/nl.1
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ nl/nl.1   15 May 2013 12:11:12 -
> @@ -0,0 +1,216 @@
> +.\"  $OpenBSD$
> +.\"  $NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
> +.\"
> +.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
> +.\" All rights reserved.
> +.\"
> +.\" This code is derived from software contributed to The NetBSD Foundation
> +.\" by Klaus Klein.
> +.\"
> +.\" Redistribution and use in source and binary forms, with or without
> +.\" modification, are permitted provided that the following conditions
> +.\" are met:
> +.\" 1. Redistributions of source code must retain the above copyright
> +.\"notice, this list of conditions and the following disclaimer.
> +.\" 2. Redistributions in binary form must reproduce the above copyright
> +.\"notice, this list of conditions and the following disclaimer in the
> +.\"documentation and/or other materials provided with the distribution.
> +.\"
> +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
> +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
> LIMITED
> +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
> PARTICULAR
> +.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
> +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
> THE
> +.\" POSSIBILITY OF SUCH DAMAGE.
> +.\"
> +.Dd $Mdocdate$
> +.Dt NL 1
> +.Os
> +.Sh NAME
> +.Nm nl
> +.Nd line numbering filter
> +.Sh SYNOPSIS
> +.Nm
> +.Op Fl p
> +.Op Fl b Ar type
> +.Op Fl d Ar delim
> +.Op Fl f Ar type
> +.Op Fl h Ar type
> +.Op Fl i Ar incr
> +.Op Fl l Ar num
> +.Op Fl n Ar format
> +.Op Fl s Ar sep
> +.Op Fl v Ar startnum
> +.Op Fl w Ar width
> +.Op Ar file
> +.Sh DESCRIPTION
> +The
> +.Nm
> +utility reads lines from the named
> +.Ar file ,
> +applies a configurable line numbering filter operation and writes the result
> +to the standard output.
> +If
> +.Ar file
> +is a single dash
> +.Pq Sq \&-
> +or absent,
> +.Nm
> +reads from the standard input.
> +.Pp
> +The
> +.Nm
> +utility treats the text it reads in terms of logical pages.
> +Unless specified otherwise, line numbering is reset at the start of each
> +logical page.
> +A logical page consists of a header, a body and a footer section; empty
> +sections are valid.
> +Different line numbering options are independently available for header,
> +body and footer sections.
> +.Pp
> +The starts of logical page sections are signaled by input lines containing
> +nothing but one of the following sequences of delimiter characters:
> +.Bd -unfilled -offset indent
> +.Bl -column "\e:\e:\e: " "header "
> +.It Em "Line""Start of"
> +.It \e:\e:\e:header
> +.It \e:\e:   body
> +.It \e:  footer
> +.El
> +.Ed

Re: off by one in vi(1)

2013-05-12 Thread Arto Jonsson
On Sat, May 11, 2013 at 05:33:20PM -0600, Todd C. Miller wrote:
> Good catch, I know folks who have hit this bug but I was never able
> to reproduce it.  Moving the isblank() check should be safe since
> trailing blanks are trimmed earlier on so we won't exit the loop
> prematurely.  I see you didn't change the TXT_ALTWERASE case, though.
> It looks like that also needs a fix but the "break" there will break
> out of the switch statement, not a loop.  However, since trailing
> blanks have already been trimmed I think that check is effectively
> a no-op and could simply be removed.

Thanks for the review. Here's an updated diff. If anyone's curious this
bug is about one month short of being 20 years old.

Index: vi/v_txt.c
===
RCS file: /cvs/src/usr.bin/vi/vi/v_txt.c,v
retrieving revision 1.22
diff -u -p -r1.22 v_txt.c
--- vi/v_txt.c  27 Oct 2009 23:59:48 -  1.22
+++ vi/v_txt.c  12 May 2013 17:24:25 -
@@ -1120,12 +1120,12 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
 */
if (LF_ISSET(TXT_TTYWERASE))
while (tp->cno > max) {
+   if (isblank(tp->lb[tp->cno - 1]))
+   break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
-   if (isblank(tp->lb[tp->cno - 1]))
-   break;
}
else {
if (LF_ISSET(TXT_ALTWERASE)) {
@@ -1133,19 +1133,17 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
-   if (isblank(tp->lb[tp->cno - 1]))
-   break;
}
if (tp->cno > max)
tmp = inword(tp->lb[tp->cno - 1]);
while (tp->cno > max) {
+   if (tmp != inword(tp->lb[tp->cno - 1])
+   || isblank(tp->lb[tp->cno - 1]))
+   break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
-   if (tmp != inword(tp->lb[tp->cno - 1])
-   || isblank(tp->lb[tp->cno - 1]))
-   break;
}
}
 



Re: add nl(1)

2013-05-10 Thread Arto Jonsson
On Fri, May 10, 2013 at 08:04:57AM +0100, Stuart Henderson wrote:
> On 2013/05/10 13:18, Damien Miller wrote:
> > On Wed, 8 May 2013, Ted Unangst wrote:
> > 
> > > On Tue, Apr 30, 2013 at 18:57, Arto Jonsson wrote:
> > > > Taken from netbsd with minor modifications. Comments?
> > > 
> > > I don't think you've received much feedback. I don't know how other
> > > developers feel, but the question I have is can't this be done with a
> > > rather simple awk script? or perl? One of the reasons we have perl in
> > > base is precisely so it can be used for things like this.
> > 
> > This implementation has the benefits of being small, having existing
> > maintainers (NetBSD) and already having been written and debugged. It
> > seems like make-work to do it over in Perl.
> 
> If we do use this implementation, then pascal@'s version from 2011 added
> some fixes from FreeBSD, http://comments.gmane.org/gmane.os.openbsd.tech/25740

Here's an updated diff. Compared to the previous diff '-' is now handled
as stdin. From the freebsd version I noticed that the previous diff also
had useless exit() call which I removed. Comments?

Index: Makefile
===
RCS file: /cvs/src/usr.bin/Makefile,v
retrieving revision 1.129
diff -u -p -r1.129 Makefile
--- Makefile15 Mar 2013 06:01:41 -  1.129
+++ Makefile10 May 2013 14:09:23 -
@@ -16,7 +16,7 @@ SUBDIR= apply apropos ar arch asa asn1_c
m4 mail make man mandoc mesg mg \
midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
newsyslog \
-   nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
+   nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
pkg-config pkill \
pr printenv printf quota radioctl ranlib rcs rdist rdistd \
readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
Index: nl/Makefile
===
RCS file: nl/Makefile
diff -N nl/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/Makefile 10 May 2013 14:09:24 -
@@ -0,0 +1,6 @@
+#  $OpenBSD$
+#  $NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
+
+PROG=  nl
+
+.include 
Index: nl/nl.1
===
RCS file: nl/nl.1
diff -N nl/nl.1
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/nl.1 10 May 2013 14:09:24 -
@@ -0,0 +1,212 @@
+.\"$OpenBSD$
+.\"$NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Klaus Klein.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd $Mdocdate$
+.Dt NL 1
+.Os
+.Sh NAME
+.Nm nl
+.Nd line numbering filter
+.Sh SYNOPSIS
+.Nm
+.Op Fl p
+.Op Fl b Ar type
+.Op Fl d Ar delim
+.Op Fl f Ar type
+.Op Fl h Ar type
+.Op Fl i Ar incr
+.Op Fl l Ar num
+.Op Fl n Ar format
+.Op Fl s Ar sep
+.Op Fl v Ar startnum
+.Op Fl w Ar width
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads lines from the named
+.Ar file
+or the standard input if the
+.Ar file
+argument is omitted,
+applies a configurable line numbering filter operation and writes the result
+to the standard output.
+.Pp
+The
+.Nm
+utility treats the 

Re: add nl(1)

2013-05-10 Thread Arto Jonsson
On Fri, May 10, 2013 at 08:04:57AM +0100, Stuart Henderson wrote:
> If we do use this implementation, then pascal@'s version from 2011 added
> some fixes from FreeBSD, http://comments.gmane.org/gmane.os.openbsd.tech/25740

I'll take a closer look at this and freebsd's code later today. There's
one bug I noticed: `nl -' should use stdin and not fail like it
does currently in all implementations.



Re: add nl(1)

2013-05-08 Thread Arto Jonsson
On Thu, May 09, 2013 at 01:13:49AM +0200, Marc Espie wrote:
> On Wed, May 08, 2013 at 04:50:16PM -0400, Ted Unangst wrote:
> > On Tue, Apr 30, 2013 at 18:57, Arto Jonsson wrote:
> > > Taken from netbsd with minor modifications. Comments?
> > 
> > I don't think you've received much feedback. I don't know how other
> > developers feel, but the question I have is can't this be done with a
> > rather simple awk script? or perl? One of the reasons we have perl in
> > base is precisely so it can be used for things like this.
> 
> nl(1) is standard, so whatever the implementation, it would be fine to
> have it.
> 
> Are you volunteering to write an awk/perl script that does this ?

I can do it in perl.



off by one in vi(1)

2013-05-07 Thread Arto Jonsson
Apr 23 -current snapshot amd64

While writing an email vi(1) crashed with segmentation fault.

When ^W (WERASE) is hit in insert mode it's possible that the line
buffer is accessed out of bounds. If 'max' == 0 and 'tp->cno' == 1 the
'tp->cno' value is first reduced by one and then 'tp->lb' is accessed at
'tp->cno' - 1. 

Index: vi/vi/v_txt.c
===
RCS file: /cvs/src/usr.bin/vi/vi/v_txt.c,v
retrieving revision 1.22
diff -u -p -r1.22 v_txt.c
--- vi/vi/v_txt.c   27 Oct 2009 23:59:48 -  1.22
+++ vi/vi/v_txt.c   7 May 2013 15:53:29 -
@@ -1120,12 +1120,12 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
 */
if (LF_ISSET(TXT_TTYWERASE))
while (tp->cno > max) {
+   if (isblank(tp->lb[tp->cno - 1]))
+   break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
-   if (isblank(tp->lb[tp->cno - 1]))
-   break;
}
else {
if (LF_ISSET(TXT_ALTWERASE)) {
@@ -1139,13 +1139,13 @@ leftmargin: tp->lb[tp->cno - 1] = ' ';
if (tp->cno > max)
tmp = inword(tp->lb[tp->cno - 1]);
while (tp->cno > max) {
+   if (tmp != inword(tp->lb[tp->cno - 1])
+   || isblank(tp->lb[tp->cno - 1]))
+   break;
--tp->cno;
++tp->owrite;
if (FL_ISSET(is_flags, IS_RUNNING))
tp->lb[tp->cno] = ' ';
-   if (tmp != inword(tp->lb[tp->cno - 1])
-   || isblank(tp->lb[tp->cno - 1]))
-   break;
}
}
 



add nl(1)

2013-04-30 Thread Arto Jonsson
Taken from netbsd with minor modifications. Comments?

Index: Makefile
===
RCS file: /cvs/src/usr.bin/Makefile,v
retrieving revision 1.129
diff -u -p -r1.129 Makefile
--- Makefile15 Mar 2013 06:01:41 -  1.129
+++ Makefile30 Apr 2013 15:22:59 -
@@ -16,7 +16,7 @@ SUBDIR= apply apropos ar arch asa asn1_c
m4 mail make man mandoc mesg mg \
midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
newsyslog \
-   nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
+   nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
pkg-config pkill \
pr printenv printf quota radioctl ranlib rcs rdist rdistd \
readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
Index: nl/Makefile
===
RCS file: nl/Makefile
diff -N nl/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/Makefile 30 Apr 2013 15:23:00 -
@@ -0,0 +1,6 @@
+#  $OpenBSD$
+#  $NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
+
+PROG=  nl
+
+.include 
Index: nl/nl.1
===
RCS file: nl/nl.1
diff -N nl/nl.1
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/nl.1 30 Apr 2013 15:23:00 -
@@ -0,0 +1,212 @@
+.\"$OpenBSD$
+.\"$NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Klaus Klein.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd $Mdocdate$
+.Dt NL 1
+.Os
+.Sh NAME
+.Nm nl
+.Nd line numbering filter
+.Sh SYNOPSIS
+.Nm
+.Op Fl p
+.Op Fl b Ar type
+.Op Fl d Ar delim
+.Op Fl f Ar type
+.Op Fl h Ar type
+.Op Fl i Ar incr
+.Op Fl l Ar num
+.Op Fl n Ar format
+.Op Fl s Ar sep
+.Op Fl v Ar startnum
+.Op Fl w Ar width
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads lines from the named
+.Ar file
+or the standard input if the
+.Ar file
+argument is omitted,
+applies a configurable line numbering filter operation and writes the result
+to the standard output.
+.Pp
+The
+.Nm
+utility treats the text it reads in terms of logical pages.
+Unless specified otherwise, line numbering is reset at the start of each
+logical page.
+A logical page consists of a header, a body and a footer section; empty
+sections are valid.
+Different line numbering options are independently available for header,
+body and footer sections.
+.Pp
+The starts of logical page sections are signaled by input lines containing
+nothing but one of the following sequences of delimiter characters:
+.Bd -unfilled -offset indent
+.Bl -column "\e:\e:\e: " "header "
+.It Em "Line"  "Start of"
+.It \e:\e:\e:  header
+.It \e:\e: body
+.It \e:footer
+.El
+.Ed
+.Pp
+If the input does not contain any logical page section signaling directives,
+the text being read is assumed to consist of a single logical page body.
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl b Ar type
+Specify the logical page body lines to be numbered.
+Recognized
+.Ar type
+arguments are:
+.Bl -tag -width pstringXX
+.It a
+Number all lines.
+.It t
+Number only non-empty lines.
+.It n
+No line numbering.
+.It p Ns Ar expr
+Number only those lines that contain the basic regular expression specified
+by
+.Ar expr .
+.El
+.Pp
+The default
+.Ar type
+for logical page body lines is t.
+.It Fl d Ar delim
+Specify the delimiter characters used to indicate the start of a logical
+page section in the input fi

RFC: add nl(1)

2012-12-22 Thread Arto Jonsson
Hi,

this patch adds nl(1) from netbsd which, if I've understood correctly,
is required by posix 2008. I've made the following changes to the code
from netbsd:

* use strtonum
* getprogname() -> __progname
* remove old RCID
* use __dead
* clean up includes

For the manual:

* remove .Pp before .Bl (spotted by mandoc lint)
* use .Ex -std

I've marked this RFC because I got some questions. 

1) On line 68 of nl.c the regex_t is intialized with zeros. Leave as it
   is? The point being if regex_t structure changes -> convert it to
   pointer?

2) Convert the program to use getline() or not?

3) The man page should probably mention confomance to posix 2008.

4) I have no idea how cvs works so I just added the $OpenBSD$ line at
   the top. This is correct?

Index: Makefile
===
RCS file: /cvs/src/usr.bin/Makefile,v
retrieving revision 1.126
diff -u -u -a -r1.126 Makefile
--- Makefile23 Nov 2012 07:03:28 -  1.126
+++ Makefile22 Dec 2012 19:51:08 -
@@ -16,7 +16,7 @@
m4 mail make man mandoc mesg mg \
midiplay mixerctl mkdep mklocale mkstr mktemp modstat nc netstat \
newsyslog \
-   nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \
+   nfsstat nice nm nl nohup oldrdist pagesize passwd paste patch pctr \
pkg-config pkill \
pr printenv printf quota radioctl ranlib rcs rdist rdistd \
readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \
Index: nl/Makefile
===
RCS file: nl/Makefile
diff -N nl/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/Makefile 22 Dec 2012 19:51:08 -
@@ -0,0 +1,6 @@
+#  $OpenBSD$
+#  $NetBSD: Makefile,v 1.4 2011/08/16 12:00:46 christos Exp $
+
+PROG=  nl
+
+.include 
Index: nl/nl.1
===
RCS file: nl/nl.1
diff -N nl/nl.1
--- /dev/null   1 Jan 1970 00:00:00 -
+++ nl/nl.1 22 Dec 2012 19:51:08 -
@@ -0,0 +1,215 @@
+.\"$OpenBSD$
+.\"$NetBSD: nl.1,v 1.12 2012/04/08 22:00:39 wiz Exp $
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Klaus Klein.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd February 15, 1999
+.Dt NL 1
+.Os
+.Sh NAME
+.Nm nl
+.Nd line numbering filter
+.Sh SYNOPSIS
+.Nm
+.Op Fl p
+.Op Fl b Ar type
+.Op Fl d Ar delim
+.Op Fl f Ar type
+.Op Fl h Ar type
+.Op Fl i Ar incr
+.Op Fl l Ar num
+.Op Fl n Ar format
+.Op Fl s Ar sep
+.Op Fl v Ar startnum
+.Op Fl w Ar width
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads lines from the named
+.Ar file
+or the standard input if the
+.Ar file
+argument is omitted,
+applies a configurable line numbering filter operation and writes the result
+to the standard output.
+.Pp
+The
+.Nm
+utility treats the text it reads in terms of logical pages.
+Unless specified otherwise, line numbering is reset at the start of each
+logical page.
+A logical page consists of a header, a body and a footer section; empty
+sections are valid.
+Different line numbering options are independently available for header,
+body and footer sections.
+.Pp
+The starts of logical page sections are signaled by input lines containing
+nothing but one of the following sequences of delimiter characters:
+.Bd -unfilled -offset indent
+.Bl -column "\e:\e:\e: " "header "
+.It Em "Line"  "Start of"
+.It \e:\e:\e:  header
+.It \e:\e: body
+.It \e:footer
+.El
+.Ed
+.Pp
+If the input does not contain any logical page section signaling dir

rs(1) segmentation fault fix

2012-12-03 Thread Arto Jonsson
Hi,

noticed this on -current (dated Dec 2) amd64:

$ who | rs
Segmentation fault (core dumped)

$ jot -r 100 | rs 10 10
Segmentation fault (core dumped)

I traced it to v1.10 of rs.c:
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/rs/rs.c.diff?r1=1.9;r2=1.10;f=h

Index: rs.c
===
RCS file: /cvs/src/usr.bin/rs/rs.c,v
retrieving revision 1.21
diff -u -r1.21 rs.c
--- rs.c4 Mar 2012 04:05:15 -   1.21
+++ rs.c3 Dec 2012 18:31:18 -
@@ -336,17 +336,16 @@
 getptrs(char **sp)
 {
char **p;
-   int newsize, gap;
+   int newsize;
 
newsize = allocsize * 2;
p = realloc(elem, newsize * sizeof(char *));
if (p == NULL)
err(1, "no memory");
 
-   gap = p - elem;
-   elem = p;
allocsize = newsize;
-   sp += gap;
+   sp += p - elem;
+   elem = p;
endelem = elem + allocsize;
return(sp);
 }



Re: upstream vendors and why they can be really harmful

2012-11-06 Thread Arto Jonsson
On Tue, Nov 06, 2012 at 01:38:32PM +0100, Marc Espie wrote:
> Basically, we have a pattern, mostly observed with kde (and a bit with
> gnome) which is really harmful for us.
> 
> ...

Relevant LWN.net article: http://lwn.net/Articles/520892/



Use .Lk instead of .Pa in URLs

2012-07-27 Thread Arto Jonsson
ditto

Index: gnu/usr.sbin/sendmail/sendmail/sendmail.8
===
RCS file: /cvs/src/gnu/usr.sbin/sendmail/sendmail/sendmail.8,v
retrieving revision 1.34
diff -u -r1.34 sendmail.8
--- gnu/usr.sbin/sendmail/sendmail/sendmail.8   17 May 2011 15:54:24 -  
1.34
+++ gnu/usr.sbin/sendmail/sendmail/sendmail.8   27 Jul 2012 08:42:35 -
@@ -693,4 +693,4 @@
 the permission problems should be fixed.
 For more information, see:
 .Pp
-.Pa http://www.sendmail.org/tips/DontBlameSendmail.html
+.Lk http://www.sendmail.org/tips/DontBlameSendmail.html
Index: kerberosV/src/lib/krb5/kerberos.8
===
RCS file: /cvs/src/kerberosV/src/lib/krb5/kerberos.8,v
retrieving revision 1.5
diff -u -r1.5 kerberos.8
--- kerberosV/src/lib/krb5/kerberos.8   7 May 2007 18:04:03 -   1.5
+++ kerberosV/src/lib/krb5/kerberos.8   27 Jul 2012 08:42:36 -
@@ -73,7 +73,7 @@
 .Pp
 For more information on how Kerberos works, and other general Kerberos
 questions see the Kerberos FAQ at
-.Pa http://www.nrl.navy.mil/CCS/people/kenh/kerberos-faq.html .
+.Lk http://www.nrl.navy.mil/CCS/people/kenh/kerberos-faq.html .
 .Pp
 For setup instructions see the Heimdal Texinfo manual.
 .Sh SEE ALSO
Index: lib/libkeynote/keynote.1
===
RCS file: /cvs/src/lib/libkeynote/keynote.1,v
retrieving revision 1.32
diff -u -r1.32 keynote.1
--- lib/libkeynote/keynote.122 Dec 2010 16:40:38 -  1.32
+++ lib/libkeynote/keynote.127 Jul 2012 08:42:37 -
@@ -276,7 +276,7 @@
 .Sh AUTHORS
 .An Angelos D. Keromytis Aq ange...@cs.columbia.edu
 .Sh WEB PAGE
-.Pa http://www1.cs.columbia.edu/~angelos/keynote.html
+.Lk http://www1.cs.columbia.edu/~angelos/keynote.html
 .Sh BUGS
 None that we know of.
 If you find any, please report them at
Index: lib/libkeynote/keynote.3
===
RCS file: /cvs/src/lib/libkeynote/keynote.3,v
retrieving revision 1.43
diff -u -r1.43 keynote.3
--- lib/libkeynote/keynote.329 Sep 2011 17:57:09 -  1.43
+++ lib/libkeynote/keynote.327 Jul 2012 08:42:37 -
@@ -898,7 +898,7 @@
 .Sh AUTHORS
 .An Angelos D. Keromytis Aq ange...@cs.columbia.edu
 .Sh WEB PAGE
-.Pa http://www1.cs.columbia.edu/~angelos/keynote.html
+.Lk http://www1.cs.columbia.edu/~angelos/keynote.html
 .Sh BUGS
 None that we know of.
 If you find any, please report them to
Index: lib/libkeynote/keynote.4
===
RCS file: /cvs/src/lib/libkeynote/keynote.4,v
retrieving revision 1.28
diff -u -r1.28 keynote.4
--- lib/libkeynote/keynote.422 Dec 2010 16:40:38 -  1.28
+++ lib/libkeynote/keynote.427 Jul 2012 08:42:37 -
@@ -895,7 +895,7 @@
 .Sh AUTHORS
 .An Angelos D. Keromytis Aq ange...@cs.columbia.edu
 .Sh WEB PAGE
-.Pa http://www1.cs.columbia.edu/~angelos/keynote.html
+.Lk http://www1.cs.columbia.edu/~angelos/keynote.html
 .Sh BUGS
 None that we know of.
 If you find any, please report them at
Index: lib/libkeynote/keynote.5
===
RCS file: /cvs/src/lib/libkeynote/keynote.5,v
retrieving revision 1.19
diff -u -r1.19 keynote.5
--- lib/libkeynote/keynote.522 Dec 2010 16:40:38 -  1.19
+++ lib/libkeynote/keynote.527 Jul 2012 08:42:37 -
@@ -695,7 +695,7 @@
 .Sh AUTHORS
 .An Angelos D. Keromytis Aq ange...@cs.columbia.edu
 .Sh WEB PAGE
-.Pa http://www1.cs.columbia.edu/~angelos/keynote.html
+.Lk http://www1.cs.columbia.edu/~angelos/keynote.html
 .Sh BUGS
 None that we know of.
 If you find any, please report them at
Index: lib/libusbhid/usbhid.3
===
RCS file: /cvs/src/lib/libusbhid/usbhid.3,v
retrieving revision 1.13
diff -u -r1.13 usbhid.3
--- lib/libusbhid/usbhid.3  16 Jul 2012 19:57:17 -  1.13
+++ lib/libusbhid/usbhid.3  27 Jul 2012 08:42:38 -
@@ -211,7 +211,7 @@
 The
 .Tn USB
 specifications can be found at:
-.Pa http://www.usb.org/developers/docs/
+.Lk http://www.usb.org/developers/docs/
 .Pp
 .Xr uhid 4 ,
 .Xr usb 4
Index: lib/libz/compress.3
===
RCS file: /cvs/src/lib/libz/compress.3,v
retrieving revision 1.10
diff -u -r1.10 compress.3
--- lib/libz/compress.3 31 May 2007 19:19:39 -  1.10
+++ lib/libz/compress.3 27 Jul 2012 08:42:38 -
@@ -2725,7 +2725,7 @@
 GZIP File Format Specification.
 .El
 .Pp
-.Pa http://www.gzip.org/zlib/
+.Lk http://www.gzip.org/zlib/
 .Sh HISTORY
 This manual page is based on an HTML version of
 .Aq Pa zlib.h
Index: sbin/isakmpd/isakmpd.conf.5
===
RCS file: /cvs/src/sbin/isakmpd/isakmpd.conf.5,v
retrieving revision 1.129
diff -u -r1.129 isakmpd.conf.5
--- sbin/isakmpd/isakmpd.conf.5 30 Jun 2012 14:51:31 -

Re: unsigned >= 0 comparisons

2012-06-25 Thread Arto Jonsson
On Mon, Jun 25, 2012 at 01:47:18PM -0600, Theo de Raadt wrote:
> Like, who cares about about commit id's.
> 
> Projects are just people working together.  A project didn't come up
> with that diff.  A person did.
> 
> When we say where something came from, we do it by giving credit, not
> by referencing some thing which will go away.

Agreed, updated:

Remove >= 0 comparisons on unsigned integers.

Diff by oga at nicotinebsd org

Index: sys/arch/amd64/amd64/machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.155
diff -u -r1.155 machdep.c
--- sys/arch/amd64/amd64/machdep.c  4 Jun 2012 15:19:47 -   1.155
+++ sys/arch/amd64/amd64/machdep.c  25 Jun 2012 18:38:30 -
@@ -1652,7 +1652,7 @@
return 1;
 
/* Low memory used for various bootstrap things */
-   if (addr >= 0 && addr < avail_start)
+   if (addr < avail_start)
return 1;
 
/*
Index: sys/dev/ic/malo.c
===
RCS file: /cvs/src/sys/dev/ic/malo.c,v
retrieving revision 1.93
diff -u -r1.93 malo.c
--- sys/dev/ic/malo.c   3 Jul 2011 21:35:38 -   1.93
+++ sys/dev/ic/malo.c   25 Jun 2012 18:38:31 -
@@ -2216,9 +2216,9 @@
 
bzero(body, sizeof(*body));
body->action = htole16(1);
-   if (powerlevel >= 0 && powerlevel < 30)
+   if (powerlevel < 30)
body->supportpowerlvl = htole16(5); /* LOW */
-   else if (powerlevel >= 30 && powerlevel < 60)
+   else if (powerlevel < 60)
body->supportpowerlvl = htole16(10);/* MEDIUM */
else
body->supportpowerlvl = htole16(15);/* HIGH */



Re: unsigned >= 0 comparisons

2012-06-25 Thread Arto Jonsson
On Mon, Jun 25, 2012 at 03:12:52PM -0400, Ted Unangst wrote:
> This is a little meta, but if we're going to start pulling changes from
> bitrig, I don't think "commit 171e1f9d" is the attribution style we
> should use.

It seems that that the branch I took these from is rebased and thus the
commit ids are now incorrect. So if a commit id is referenced it should
be referenced in a branch that doesn't get rebased (probably master in
this case).

-- 
Arto Jonsson



Re: unsigned >= 0 comparisons

2012-06-25 Thread Arto Jonsson
On Mon, Jun 25, 2012 at 07:23:44PM +0100, Nigel Taylor wrote:
> In place of
>   else if (powerlevel >= 30 && powerlevel < 60)
> could use
>   else if (powerlevel < 60)
> 

Thanks. Updated patch below.

Index: sys/arch/amd64/amd64/machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.155
diff -u -r1.155 machdep.c
--- sys/arch/amd64/amd64/machdep.c  4 Jun 2012 15:19:47 -   1.155
+++ sys/arch/amd64/amd64/machdep.c  25 Jun 2012 18:38:30 -
@@ -1652,7 +1652,7 @@
return 1;
 
/* Low memory used for various bootstrap things */
-   if (addr >= 0 && addr < avail_start)
+   if (addr < avail_start)
return 1;
 
/*
Index: sys/dev/ic/malo.c
===
RCS file: /cvs/src/sys/dev/ic/malo.c,v
retrieving revision 1.93
diff -u -r1.93 malo.c
--- sys/dev/ic/malo.c   3 Jul 2011 21:35:38 -   1.93
+++ sys/dev/ic/malo.c   25 Jun 2012 18:38:31 -
@@ -2216,9 +2216,9 @@
 
bzero(body, sizeof(*body));
body->action = htole16(1);
-   if (powerlevel >= 0 && powerlevel < 30)
+   if (powerlevel < 30)
body->supportpowerlvl = htole16(5); /* LOW */
-   else if (powerlevel >= 30 && powerlevel < 60)
+   else if (powerlevel < 60)
body->supportpowerlvl = htole16(10);/* MEDIUM */
else
body->supportpowerlvl = htole16(15);/* HIGH */



unsigned >= 0 comparisons

2012-06-25 Thread Arto Jonsson
Hi,

a couple of >= 0 comparisons on unsigned integers. These refer to Bitrig
commits 171e1f9d and 72337965 respectively.

Index: sys/arch/amd64/amd64/machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.155
diff -u -r1.155 machdep.c
--- sys/arch/amd64/amd64/machdep.c  4 Jun 2012 15:19:47 -   1.155
+++ sys/arch/amd64/amd64/machdep.c  25 Jun 2012 17:28:29 -
@@ -1652,7 +1652,7 @@
return 1;
 
/* Low memory used for various bootstrap things */
-   if (addr >= 0 && addr < avail_start)
+   if (addr < avail_start)
return 1;
 
/*
Index: sys/dev/ic/malo.c
===
RCS file: /cvs/src/sys/dev/ic/malo.c,v
retrieving revision 1.93
diff -u -r1.93 malo.c
--- sys/dev/ic/malo.c   3 Jul 2011 21:35:38 -   1.93
+++ sys/dev/ic/malo.c   25 Jun 2012 17:28:30 -
@@ -2216,7 +2216,7 @@
 
bzero(body, sizeof(*body));
body->action = htole16(1);
-   if (powerlevel >= 0 && powerlevel < 30)
+   if (powerlevel < 30)
body->supportpowerlvl = htole16(5); /* LOW */
else if (powerlevel >= 30 && powerlevel < 60)
body->supportpowerlvl = htole16(10);/* MEDIUM */



Re: grep: use queue(3)

2012-02-19 Thread Arto Jonsson
On Sat, Feb 18, 2012 at 01:23:36PM -0800, Philip Guenther wrote:
> On Sat, Feb 18, 2012 at 12:20 PM, Arto Jonsson  wrote:
> > Use queue(3) macros instead of own internal queue implementation. No
> > functional change.
> ...
> > -typedef struct queue {
> > - B  B  B  struct queue B  *next;
> > - B  B  B  str_t B  B  B  B  B  data;
> > -} queue_t;
> 
> So, the current queue puts the link in the same allocated block as the
> str_t data.
> 
> > -static queue_t *q_head, *q_tail;
> > -static int B  B  B count;
> > +struct q_entry {
> > + B  B  B  str_t* data;
> > + B  B  B  SIMPLEQ_ENTRY(q_entry) q_entries;
> > +};
> > +SIMPLEQ_HEAD(, q_entry) q_head = SIMPLEQ_HEAD_INITIALIZER(q_head);
> 
> Why do you switch to putting the links in separate blocks from the
> str_t data?  I.e., why the "*" in "str_t* data" and thus the extra
> mallocs and frees in the code to create and destroy them?
> 
> 
> Philip Guenther
> 

Updated patch.

Index: grep.h
===
RCS file: /cvs/src/usr.bin/grep/grep.h,v
retrieving revision 1.17
diff -u -r1.17 grep.h
--- grep.h  8 Jul 2011 01:20:24 -   1.17
+++ grep.h  19 Feb 2012 07:39:30 -
@@ -89,7 +89,6 @@
 voidfgrepcomp(fastgrep_t *, const char *);
 
 /* queue.c */
-voidinitqueue(void);
 voidenqueue(str_t *x);
 voidprintqueue(void);
 voidclearqueue(void);
Index: queue.c
===
RCS file: /cvs/src/usr.bin/grep/queue.c,v
retrieving revision 1.6
diff -u -r1.6 queue.c
--- queue.c 8 Jul 2011 01:20:24 -   1.6
+++ queue.c 19 Feb 2012 07:39:30 -
@@ -26,97 +26,66 @@
  * SUCH DAMAGE.
  */
 
-/*
- * A really poor man's queue.  It does only what it has to and gets out of
- * Dodge.
- */
-
 #include 
+#include 
 
 #include 
 #include 
 
 #include "grep.h"
 
-typedef struct queue {
-   struct queue   *next;
-   str_t   data;
-} queue_t;
-
-static queue_t *q_head, *q_tail;
-static int  count;
+struct q_entry {
+   SIMPLEQ_ENTRY(q_entry) q_entries;
+   str_t data;
+};
+SIMPLEQ_HEAD(, q_entry) q_head = SIMPLEQ_HEAD_INITIALIZER(q_head);
 
-static queue_t *dequeue(void);
-
-void
-initqueue(void)
-{
-   q_head = q_tail = NULL;
-}
-
-static void
-free_item(queue_t *item)
-{
-   free(item);
-}
+static int count;
+static struct q_entry  *dequeue(void);
 
 void
 enqueue(str_t *x)
 {
-   queue_t *item;
+   struct q_entry* e;
 
-   item = grep_malloc(sizeof *item + x->len);
-   item->data.len = x->len;
-   item->data.line_no = x->line_no;
-   item->data.off = x->off;
-   item->data.dat = (char *)item + sizeof *item;
-   memcpy(item->data.dat, x->dat, x->len);
-   item->data.file = x->file;
-   item->next = NULL;
-
-   if (!q_head) {
-   q_head = q_tail = item;
-   } else {
-   q_tail->next = item;
-   q_tail = item;
-   }
+   e = grep_malloc(sizeof(struct q_entry) + x->len);
+   e->data.len = x->len;
+   e->data.line_no = x->line_no;
+   e->data.off = x->off;
+   e->data.dat = (char *)e + sizeof(struct q_entry);
+   memcpy(e->data.dat, x->dat, x->len);
+   e->data.file = x->file;
+
+   SIMPLEQ_INSERT_TAIL(&q_head, e, q_entries);
 
if (++count > Bflag)
-   free_item(dequeue());
+   free(dequeue());
 }
 
-static queue_t *
+struct q_entry *
 dequeue(void)
 {
-   queue_t *item;
-
-   if (q_head == NULL)
-   return NULL;
-
+   struct q_entry *e;
--count;
-   item = q_head;
-   q_head = item->next;
-   if (q_head == NULL)
-   q_tail = NULL;
-   return item;
+   e = SIMPLEQ_FIRST(&q_head);
+   SIMPLEQ_REMOVE_HEAD(&q_head, q_entries);
+   return e;
 }
 
 void
 printqueue(void)
 {
-   queue_t *item;
-
-   while ((item = dequeue()) != NULL) {
-   printline(&item->data, '-', NULL);
-   free_item(item);
+   struct q_entry *e;
+   while (!SIMPLEQ_EMPTY(&q_head)) {
+   e = dequeue();
+   printline(&e->data, '-', NULL);
+   free(e);
}
 }
 
 void
 clearqueue(void)
 {
-   queue_t *item;
-
-   while ((item = dequeue()) != NULL)
-   free_item(item);
+   while (!SIMPLEQ_EMPTY(&q_head))
+   free(dequeue());
 }
Index: util.c
===
RCS file: /cvs/src/usr.bin/grep/util.c,v
retrieving revision 1.42
diff -u -r1.42 util.c
--- util.c  17 Jul 2011 19:39:21 -  1.42
+++ util.c  19 Feb 2012 07:39:30 -
@@ -119,8 +119,6 @@
tail = 0;
ln.off = -1;
 
-   if (Bflag > 0)
-   initqueue();
for (c = 0;  c == 0 || !(lflag || qflag); ) {
ln.off += ln.len + 1;
if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL)



grep: use queue(3)

2012-02-18 Thread Arto Jonsson
Use queue(3) macros instead of own internal queue implementation. No
functional change.

Index: grep.h
===
RCS file: /cvs/src/usr.bin/grep/grep.h,v
retrieving revision 1.17
diff -u -r1.17 grep.h
--- grep.h  8 Jul 2011 01:20:24 -   1.17
+++ grep.h  18 Feb 2012 20:14:38 -
@@ -89,7 +89,6 @@
 voidfgrepcomp(fastgrep_t *, const char *);
 
 /* queue.c */
-voidinitqueue(void);
 voidenqueue(str_t *x);
 voidprintqueue(void);
 voidclearqueue(void);
Index: queue.c
===
RCS file: /cvs/src/usr.bin/grep/queue.c,v
retrieving revision 1.6
diff -u -r1.6 queue.c
--- queue.c 8 Jul 2011 01:20:24 -   1.6
+++ queue.c 18 Feb 2012 20:14:38 -
@@ -26,97 +26,77 @@
  * SUCH DAMAGE.
  */
 
-/*
- * A really poor man's queue.  It does only what it has to and gets out of
- * Dodge.
- */
-
 #include 
+#include 
 
 #include 
 #include 
 
 #include "grep.h"
 
-typedef struct queue {
-   struct queue   *next;
-   str_t   data;
-} queue_t;
-
-static queue_t *q_head, *q_tail;
-static int  count;
+struct q_entry {
+   str_t* data;
+   SIMPLEQ_ENTRY(q_entry) q_entries;
+};
+SIMPLEQ_HEAD(, q_entry) q_head = SIMPLEQ_HEAD_INITIALIZER(q_head);
 
-static queue_t *dequeue(void);
-
-void
-initqueue(void)
-{
-   q_head = q_tail = NULL;
-}
+static int count;
+static struct q_entry  *dequeue(void);
 
 static void
-free_item(queue_t *item)
+free_item(struct q_entry *e)
 {
-   free(item);
+   free(e->data);
+   free(e);
 }
 
 void
 enqueue(str_t *x)
 {
-   queue_t *item;
+   struct q_entry* e;
+   str_t *s;
 
-   item = grep_malloc(sizeof *item + x->len);
-   item->data.len = x->len;
-   item->data.line_no = x->line_no;
-   item->data.off = x->off;
-   item->data.dat = (char *)item + sizeof *item;
-   memcpy(item->data.dat, x->dat, x->len);
-   item->data.file = x->file;
-   item->next = NULL;
-
-   if (!q_head) {
-   q_head = q_tail = item;
-   } else {
-   q_tail->next = item;
-   q_tail = item;
-   }
+   s = grep_malloc(sizeof(str_t) + x->len);
+   s->len = x->len;
+   s->line_no = x->line_no;
+   s->off = x->off;
+   s->dat = (char *)s + sizeof(str_t);
+   memcpy(s->dat, x->dat, x->len);
+   s->file = x->file;
+
+   e = grep_malloc(sizeof(struct q_entry));
+   e->data = s;
+   SIMPLEQ_INSERT_TAIL(&q_head, e, q_entries);
 
if (++count > Bflag)
free_item(dequeue());
 }
 
-static queue_t *
+struct q_entry *
 dequeue(void)
 {
-   queue_t *item;
-
-   if (q_head == NULL)
-   return NULL;
-
+   struct q_entry *e;
--count;
-   item = q_head;
-   q_head = item->next;
-   if (q_head == NULL)
-   q_tail = NULL;
-   return item;
+   e = SIMPLEQ_FIRST(&q_head);
+   SIMPLEQ_REMOVE_HEAD(&q_head, q_entries);
+   return e;
 }
 
 void
 printqueue(void)
 {
-   queue_t *item;
-
-   while ((item = dequeue()) != NULL) {
-   printline(&item->data, '-', NULL);
-   free_item(item);
+   struct q_entry *e;
+   while (!SIMPLEQ_EMPTY(&q_head)) {
+   e = dequeue();
+   printline(e->data, '-', NULL);
+   free_item(e);
}
 }
 
 void
 clearqueue(void)
 {
-   queue_t *item;
-
-   while ((item = dequeue()) != NULL)
-   free_item(item);
+   while (!SIMPLEQ_EMPTY(&q_head)) {
+   free_item(dequeue());
+   }
 }
Index: util.c
===
RCS file: /cvs/src/usr.bin/grep/util.c,v
retrieving revision 1.42
diff -u -r1.42 util.c
--- util.c  17 Jul 2011 19:39:21 -  1.42
+++ util.c  18 Feb 2012 20:14:38 -
@@ -119,8 +119,6 @@
tail = 0;
ln.off = -1;
 
-   if (Bflag > 0)
-   initqueue();
for (c = 0;  c == 0 || !(lflag || qflag); ) {
ln.off += ln.len + 1;
if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL)



Re: Minor morse(6) patch

2012-02-18 Thread Arto Jonsson
Just noticed this is useless. Sorry for the noise.

On Sat, Feb 18, 2012 at 07:01:39PM +0200, Arto Jonsson wrote:
> Make the lookup tables const.
> 
> Index: morse.c
> ===
> RCS file: /cvs/src/games/morse/morse.c,v
> retrieving revision 1.14
> diff -u -r1.14 morse.c
> --- morse.c   27 Oct 2009 23:59:26 -  1.14
> +++ morse.c   18 Feb 2012 16:47:27 -
> @@ -35,7 +35,7 @@
>  #include 
>  #include 
>  
> -static char
> +static const char
>   *digit[] = {
>   "-",
>   ".",
> @@ -80,7 +80,9 @@
>  struct punc {
>   char c;
>   char *morse;
> -} other[] = {
> +};
> +
> +static const struct punc other[] = {
>   { ',', "--..--" },
>   { '.', ".-.-.-" },
>   { '?', "..--.." },
> @@ -100,8 +102,8 @@
>  };
>  
>  void morse(int);
> -void decode(char *);
> -void show(char *);
> +void decode(const char *);
> +void show(const char *);
>  
>  static int sflag = 0;
>  static int dflag = 0;
> @@ -206,7 +208,7 @@
>  }
>  
>  void
> -decode(char *s)
> +decode(const char *s)
>  {
>   int i;
>   
> @@ -235,7 +237,7 @@
>  
>  
>  void
> -show(char *s)
> +show(const char *s)
>  {
>   if (sflag)
>   printf(" %s", s);



Minor morse(6) patch

2012-02-18 Thread Arto Jonsson
Make the lookup tables const.

Index: morse.c
===
RCS file: /cvs/src/games/morse/morse.c,v
retrieving revision 1.14
diff -u -r1.14 morse.c
--- morse.c 27 Oct 2009 23:59:26 -  1.14
+++ morse.c 18 Feb 2012 16:47:27 -
@@ -35,7 +35,7 @@
 #include 
 #include 
 
-static char
+static const char
*digit[] = {
"-",
".",
@@ -80,7 +80,9 @@
 struct punc {
char c;
char *morse;
-} other[] = {
+};
+
+static const struct punc other[] = {
{ ',', "--..--" },
{ '.', ".-.-.-" },
{ '?', "..--.." },
@@ -100,8 +102,8 @@
 };
 
 void   morse(int);
-void   decode(char *);
-void   show(char *);
+void   decode(const char *);
+void   show(const char *);
 
 static int sflag = 0;
 static int dflag = 0;
@@ -206,7 +208,7 @@
 }
 
 void
-decode(char *s)
+decode(const char *s)
 {
int i;

@@ -235,7 +237,7 @@
 
 
 void
-show(char *s)
+show(const char *s)
 {
if (sflag)
printf(" %s", s);



Minor fixes for bs(6) manual

2011-07-04 Thread Arto Jonsson
Hi,

some minor fixes in bs(6) manual:

- use `Ds' for indentation
- re-order the arguments list so its order matches SYNOPSIS


Index: games/bs/bs.6
===
RCS file: /cvs/src/games/bs/bs.6,v
retrieving revision 1.13
diff -u -r1.13 bs.6
--- games/bs/bs.6   20 May 2008 14:42:09 -  1.13
+++ games/bs/bs.6   1 Jul 2011 19:01:51 -
@@ -58,16 +58,12 @@
 will force a screen redraw.
 .Pp
 The command-line arguments control game modes:
-.Bl -tag -width XxXXX
+.Bl -tag -width Ds
 .It Fl b
 Selects a
 .Sq blitz
 variant.
 This allows a side to shoot for as long as it continues to score hits.
-.It Fl c
-Permits ships to be placed adjacently.
-Normally, ships must be separated by at least one square of open water.
-This disables that check and allows them to close-pack.
 .It Fl s
 Selects a
 .Sq salvo
@@ -77,6 +73,10 @@
 This puts a premium on scoring hits early and knocking out
 some ships and also makes it much harder, for example, when you face a superior
 force with only your PT-boat.
+.It Fl c
+Permits ships to be placed adjacently.
+Normally, ships must be separated by at least one square of open water.
+This disables that check and allows them to close-pack.
 .El
 .Sh AUTHORS
 Originally written by one Bruce Holloway in 1986.