Re: ed: Make use of stderr compliant with POSIX

2022-11-18 Thread Todd C . Miller
On Sun, 25 Sep 2022 13:12:44 +0200, =?UTF-8?Q?S=C3=B6ren?= Tempel wrote:

> Currently, the OpenBSD ed implementation incorrectly writes information
> to standard error that should be written to standard out (as per POSIX).
>
> For the read and write command the POSIX standard states the following:
>
>   If the command is successful, the number of bytes written shall
>   be written to standard output [...]
>
> However, OpenBSD ed presently writes the number of bytes (for both the
> read and the write command) to standard error. Furthermore, the POSIX
> standard mandates that the infamous "?\n" error string should also be
> written to standard output while OpenBSD ed presently writes the string
> to standard error.

Committed, thanks.

 - todd



Re: relayd: always call va_end

2022-11-09 Thread Todd C . Miller
Yes, OK millert@

 - todd



Re: pause.3: misc cleanup

2022-11-09 Thread Todd C . Miller
On Wed, 09 Nov 2022 16:47:22 +, Scott Cheloha wrote:

> I think this could use some sprucing.
>
> NAME
>
> - "stop until signal" -> "wait for a signal"
>
>   Feels more natural to me.

OK

> DESCRIPTION
>
> - It's "the calling thread" that blocks, not "a process".
>
> - Nothing is "forced".
>
> - It "blocks", it doesn't "pause".  Saying pause(3) "pauses"
>   is too circular.

Block seems better to me too.  Sleep would also work that may be
less precise.

> - No need to enumerate the ways a signal can be delivered.  That is
>   better left to other manpages.  Nix kill(2) and setitimer(2) from
>   the DESCRIPTION.
>
> - No need to mention that we don't return until the signal handler
>   returns either, that's just basic signal(3) stuff.

OK.

> - Should we explicitly mention the underlying implementation system
>   calls or not?  I'm unsure.

I don't think there is any reason to document the implementation
details.

> RETURN VALUES
>
> - Pull ERRORS into this section.  No need to put the one error in a
>   .Bl/.El, we can just mention it inline.

OK

> SEE ALSO
>
> - Nix select(2) and setitimer(2), they aren't directly relevant.

OK.  The reason select(2) is there is probably because you can
emulate pause() using select().

> - Add sigprocmask(2) and signal(3).  They are very relevant.

OK.

> HISTORY
>
> - We still have sigpause(3) and sigblock(3) in userspace.  Should
>   we .Xr them?  They aren't systems calls anymore, but they were
>   at that time.  Unsure what to do here.

I think it is better to use .Fn for sigpause(3) and sigblock(3)
rather than .Xr here.

Note that in 4.3-Reno pause(3) was still implemented in terms of
sigpause(3) and sigblock(3), it is just that those functions were
themselves wrappers instead of system calls.  Personally, I would
drop the bit about 4.3-Reno since it is not really correct in my
opinion.

 - todd



Re: ftp: strnvis redirect uri

2022-11-09 Thread Todd C . Miller
On Wed, 09 Nov 2022 17:33:54 +0100, Claudio Jeker wrote:

> Like this?

Yes, OK millert@

 - todd



Re: ftp: allow for more spaces in http headers

2022-11-09 Thread Todd C . Miller
On Wed, 09 Nov 2022 16:21:46 +0100, Claudio Jeker wrote:

> This is the changes that I added to rpki-client http.c which I have not
> yet merged into ftp(1)

OK millert@

 - todd



Re: ftp: strnvis redirect uri

2022-11-09 Thread Todd C . Miller
On Wed, 09 Nov 2022 15:46:06 +, Florian Obser wrote:

> 200 might be a bit short for an URL, no?

Perhaps stravis(3) is a better choice then?

 - todd



Re: ftp: strnvis redirect uri

2022-11-09 Thread Todd C . Miller
On Wed, 09 Nov 2022 16:34:20 +0100, Claudio Jeker wrote:

> The redirect URI is untrusted input so strnvis it first before printing
> it.

OK millert@

 - todd



[no subject]

2022-11-08 Thread Todd C . Miller
On Tue, 08 Nov 2022 18:05:24 +, Klemens Nanni wrote:

> Subject: Document ifc_list immutability

Sure.  OK millert@

 - todd



Re: libcrypto: fix leak in BN_mpi2bn()

2022-11-08 Thread Todd C . Miller
On Tue, 08 Nov 2022 18:33:48 +0100, Tobias Heider wrote:

> If ain == NULL then a points to newly malloced memory which should be
> freed when BN_bin2bn() fails.

We don't have an "ain" function argument in LibreSSL so you will
need a larger diff.  Perhaps something like this (untested).

 - todd

Index: lib/libcrypto/bn/bn_mpi.c
===
RCS file: /cvs/src/lib/libcrypto/bn/bn_mpi.c,v
retrieving revision 1.8
diff -u -p -u -r1.8 bn_mpi.c
--- lib/libcrypto/bn/bn_mpi.c   29 Jan 2017 17:49:22 -  1.8
+++ lib/libcrypto/bn/bn_mpi.c   8 Nov 2022 18:03:36 -
@@ -92,8 +92,9 @@ BN_bn2mpi(const BIGNUM *a, unsigned char
 }
 
 BIGNUM *
-BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a)
+BN_mpi2bn(const unsigned char *d, int n, BIGNUM *ain)
 {
+   BIGNUM *a = ain;
long len;
int neg = 0;
 
@@ -121,8 +122,11 @@ BN_mpi2bn(const unsigned char *d, int n,
d += 4;
if ((*d) & 0x80)
neg = 1;
-   if (BN_bin2bn(d, (int)len, a) == NULL)
+   if (BN_bin2bn(d, (int)len, a) == NULL) {
+   if (ain == NULL)
+   BN_free(a);
return (NULL);
+   }
a->neg = neg;
if (neg) {
BN_clear_bit(a, BN_num_bits(a) - 1);



Re: usbdevs(8) getopt tweak

2022-10-27 Thread Todd C . Miller
On Fri, 28 Oct 2022 12:03:15 +1000, David Gwynne wrote:

> usbdevs has "?" in the optstring is passes to getopt, but doesn't handle
> it specially. this is unnecessarily different to everything else in the
> tree, so i want to remove it. ok?

Sure, OK millert@

 - todd



compress: remove cat_opts and decomp_opts, add static

2022-10-22 Thread Todd C . Miller
The cat_opts and decomp_opts fields in struct compressor are unused
so just remove them.  Also mark functions unused outside of main.c
as static.

 - todd

Index: usr.bin/compress/main.c
===
RCS file: /cvs/src/usr.bin/compress/main.c,v
retrieving revision 1.102
diff -u -p -u -r1.102 main.c
--- usr.bin/compress/main.c 22 Oct 2022 14:41:27 -  1.102
+++ usr.bin/compress/main.c 22 Oct 2022 20:06:43 -
@@ -61,9 +61,7 @@ const struct compressor {
const char *name;
const char *suffix;
const u_char *magic;
-   const char *comp_opts;
-   const char *decomp_opts;
-   const char *cat_opts;
+   const char *opts;
void *(*ropen)(int, char *, int);
int (*read)(void *, char *, int);
 #ifndef SMALL
@@ -78,8 +76,6 @@ const struct compressor {
".gz",
"\037\213",
"123456789ab:cdfhkLlNnOo:qrS:tVv",
-   "cfhkLlNno:qrtVv",
-   "fhqr",
gz_ropen,
gz_read,
 #ifndef SMALL
@@ -95,8 +91,6 @@ const struct compressor {
".Z",
"\037\235",
"123456789ab:cdfghlNnOo:qrS:tv",
-   "cfhlNno:qrtv",
-   "fghqr",
z_ropen,
zread,
z_wopen,
@@ -109,8 +103,6 @@ const struct compressor {
".zip",
"PK",
NULL,
-   "cfhkLlNno:qrtVv",
-   "fhqr",
zip_ropen,
zip_read,
NULL,
@@ -127,8 +119,6 @@ const struct compressor null_method = {
".nul",
"XX",
"123456789ab:cdfghlNnOo:qrS:tv",
-   "cfhlNno:qrtv",
-   "fghqr",
null_ropen,
null_read,
null_wopen,
@@ -137,19 +127,19 @@ const struct compressor null_method = {
 };
 #endif /* SMALL */
 
-int permission(const char *);
-__dead void usage(int);
-int docompress(const char *, char *, const struct compressor *,
+static int permission(const char *);
+static __dead void usage(int);
+static int docompress(const char *, char *, const struct compressor *,
 int, struct stat *);
-int dodecompress(const char *, char *, struct stat *);
-const struct compressor *check_method(int);
-const char *check_suffix(const char *);
-char *set_outfile(const char *, char *, size_t);
-void list_stats(const char *, const struct compressor *, struct z_info *);
-void verbose_info(const char *, off_t, off_t, u_int32_t);
+static int dodecompress(const char *, char *, struct stat *);
+static const char *check_suffix(const char *);
+static char *set_outfile(const char *, char *, size_t);
+static void list_stats(const char *, const struct compressor *,
+struct z_info *);
+static void verbose_info(const char *, off_t, off_t, u_int32_t);
 
-const struct option longopts[] = {
 #ifndef SMALL
+const struct option longopts[] = {
{ "ascii",  no_argument,0, 'a' },
{ "stdout", no_argument,0, 'c' },
{ "to-stdout",  no_argument,0, 'c' },
@@ -170,9 +160,11 @@ const struct option longopts[] = {
{ "version",no_argument,0, 'V' },
{ "fast",   no_argument,0, '1' },
{ "best",   no_argument,0, '9' },
-#endif /* SMALL */
{ NULL }
 };
+#else /* SMALL */
+const struct option *longopts = NULL;
+#endif /* SMALL */
 
 int
 main(int argc, char *argv[])
@@ -202,7 +194,7 @@ main(int argc, char *argv[])
method = M_COMPRESS;
 #endif /* SMALL */
}
-   optstr = method->comp_opts;
+   optstr = method->opts;
 
decomp = 0;
pmode = MODE_COMP;
@@ -617,7 +609,7 @@ docompress(const char *in, char *out, co
 #endif
 }
 
-const struct compressor *
+static const struct compressor *
 check_method(int fd)
 {
const struct compressor *method;
@@ -640,7 +632,7 @@ check_method(int fd)
return (NULL);
 }
 
-int
+static int
 dodecompress(const char *in, char *out, struct stat *sb)
 {
const struct compressor *method;
@@ -690,7 +682,7 @@ dodecompress(const char *in, char *out, 
return (FAILURE);
}
if (storename && oldname[0] != '\0') {
-   char *oldbase = basename(oldname);
+   const char *oldbase = basename(oldname);
char *cp = strrchr(out, '/');
if (cp != NULL) {
*(cp + 1) = '\0';
@@ -834,7 +826,7 @@ setfile(const char *name, int fd, struct
warn("futimens: %s", name);
 }
 
-int
+static int
 permission(const char *fname)
 {
int ch, first;
@@ -851,7 +843,7 @@ permission(const char *fname)
 /*
  * Check infile for a known suffix and return the suffix portion or NULL.
  */
-const char *
+static const char *
 check_suffix(const char *infile)
 {
int i;
@@ -878,7 +870,7 @@ check_suffix(const char *infile)
  * Set 

Re: sparc64: constify ddb instruction table

2022-10-21 Thread Todd C . Miller
On Fri, 21 Oct 2022 22:55:57 +0200, Mark Kettenis wrote:

> Be careful.  By moving more stuff into .rodata, you may overflow the
> .text/.rodata block.  Make sure you build and test the kernels and
> also test an actual bsd.rd.

Do we know exactly what these limits are?  If so, couldn't we test
for them in the kernel Makefile after the kernel is linked?

 - todd



Re: smtpd bug in Received: header with one recipient

2022-10-19 Thread Todd C . Miller
I took another look at this and it seems correct to me.  We should
not really be using tx->evp.rcpt after the it has been added to the
tx->rcpts list.

I plan to commit it unless there are objections.

 - todd



Re: gunzip: support .zip files with a single member

2022-10-17 Thread Todd C . Miller
eck_suffix(const char *infile)
 {
int i;
-   char *suf, *sep, *separators = ".-_";
-   static char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", NULL };
+   const char *suf, *sep;
+   const char separators[] = ".-_";
+   const char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", NULL };
 
for (sep = separators; *sep != '\0'; sep++) {
if ((suf = strrchr(infile, *sep)) == NULL)
continue;
suf++;
 
+   if (strcmp(suf, suffix + 1) == 0)
+   return (suf - 1);
for (i = 0; suffixes[i] != NULL; i++) {
if (strcmp(suf, suffixes[i]) == 0)
return (suf - 1);
Index: usr.bin/compress/zipopen.c
=======
RCS file: usr.bin/compress/zipopen.c
diff -N usr.bin/compress/zipopen.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.bin/compress/zipopen.c  14 Oct 2022 00:20:46 -
@@ -0,0 +1,454 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2022 Todd C. Miller 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "compress.h"
+
+#define MINIMUM(a, b)  (((a) < (b)) ? (a) : (b))
+
+/* Signatures for zip file headers we use. */
+#define ZIPMAG 0x4b50  /* first two bytes of the zip signature */
+#define LOCREM 0x0403  /* remaining two bytes in zip signature */
+#define LOCSIG 0x04034b50  /* local file header signature */
+#define EXTSIG 0x08074b50  /* extended local header signature */
+
+/* Header sizes. */
+#define LOCHDR 30  /* size of local header, including signature */
+#define EXTHDR 16  /* size of extended local header, inc sig */
+
+/* General purpose flag bits. */
+#define CRPFLG 1   /* flag bit for encrypted entry */
+#define EXTFLG 8   /* flag bit for extended local header */
+
+/* Extra field definitions */
+#defineEF_ZIP640x0001  /* zip64 support */
+#defineEF_TIME 0x5455  /* mtime, atime, ctime in UTC ("UT") */
+#define EF_IZUNIX  0x5855  /* UNIX extra field ID ("UX") */
+
+#define Z_STORED 0 /* Stored uncompressed in .zip */
+
+struct zip_state {
+   z_stream z_stream;  /* libz stream */
+   uint8_t  z_buf[Z_BUFSIZE]; /* I/O buffer */
+   uint8_t  z_eof; /* set if end of input file */
+   uint8_t  z_zip64;   /* 64-bit file sizes */
+   uint16_t z_method;  /* Z_DEFLATE or Z_STORED */
+   uint16_t z_flags;   /* general purpose flags */
+   int  z_fd;  /* zip file descriptor */
+   uint32_t z_time;/* timestamp (mtime) */
+   uint32_t z_crc; /* crc32 of uncompressed data */
+   uint32_t z_ocrc;/* crc32 of uncompressed data (from header) */
+   uint32_t z_hlen;/* length of the zip header */
+   uint64_t z_ulen;/* uncompressed data length (from header) */
+   uint64_t z_total_in;/* # bytes in */
+   uint64_t z_total_out;   /* # bytes out */
+};
+
+static int
+get_byte(struct zip_state *s)
+{
+   if (s->z_eof)
+   return EOF;
+
+   if (s->z_stream.avail_in == 0) {
+   ssize_t nread = read(s->z_fd, s->z_buf, Z_BUFSIZE);
+   if (nread <= 0) {
+   s->z_eof = 1;
+   return EOF;
+   }
+   s->z_stream.avail_in = nread;
+   s->z_stream.next_in = s->z_buf;
+   }
+   s->z_stream.avail_in--;
+   return *s->z_stream.next_in++;
+}
+
+static uint16_t
+get_uint16(struct zip_state *s)
+{
+   uint16_t x;
+
+   x  = ((uint16_t)(get_byte(s) & 0xff));
+   x |= ((uint16_t)(get_byte(s) & 0xff))<<8;
+   return x;
+}
+
+static uint32_t
+get_uint32(struct zip_state *s)
+{
+   uint32_t x;
+
+   x  = ((uint32_t)(get_byte(s) & 0xff));
+   x |= ((uint32_t)(get_byte(s) & 0xff))<<8;
+   x |= ((uint32_t)(get_byte(s) 

Re: gunzip: support .zip files with a single member

2022-10-13 Thread Todd C . Miller
On Thu, 13 Oct 2022 14:14:28 -0600, "Todd C. Miller" wrote:

> GNU gzip support uncompressing .zip files that contain a single
> member.  This can be very convenient when dealing with email
> attachments that use zip instead of gzip to compress a single file
> (I'm looking at you Google).  Below is a diff to support this with
> our gzip.  This turned out to be more complicated than I expected
> simply due to the number of zip extended header fields.
>
> If there is more than a single file in the .zip we extract the first
> one but leave the origin .zip file alone.  I made some minor tweaks
> to main.c to support this.  We now only remove the output file if
> error is set to FAILURE, not WARNING.  This has the side effect
> that the output file is no longer removed simply due to a crc error,
> which I think is an improvement.

I found a problem with my previous version reporting crc errors for
larger files.  That is fixed in the version below.  With the latest
diff here is the size of distrib/special/gzip on amd64:

Old:
textdatabss dec hex
184591  777629104   221471  3611f

New:
textdatabss dec hex
184559  777629104   221439  360ff

There is now a net decrease in size :-)

 - todd

Index: usr.bin/compress/Makefile
===
RCS file: /cvs/src/usr.bin/compress/Makefile,v
retrieving revision 1.22
diff -u -p -u -r1.22 Makefile
--- usr.bin/compress/Makefile   30 Mar 2016 06:38:45 -  1.22
+++ usr.bin/compress/Makefile   13 Oct 2022 19:33:57 -
@@ -1,7 +1,7 @@
 #  $OpenBSD: Makefile,v 1.22 2016/03/30 06:38:45 jmc Exp $
 
 PROG=  compress
-SRCS=  main.c zopen.c gzopen.c nullopen.c
+SRCS=  main.c zopen.c gzopen.c zipopen.c nullopen.c
 MAN=   compress.1 gzexe.1 gzip.1 zdiff.1 zforce.1 zmore.1 znew.1
 LINKS= ${BINDIR}/compress ${BINDIR}/uncompress \
${BINDIR}/compress ${BINDIR}/zcat \
Index: usr.bin/compress/compress.h
===
RCS file: /cvs/src/usr.bin/compress/compress.h,v
retrieving revision 1.14
diff -u -p -u -r1.14 compress.h
--- usr.bin/compress/compress.h 18 Jan 2021 00:46:58 -  1.14
+++ usr.bin/compress/compress.h 13 Oct 2022 19:34:49 -
@@ -65,13 +65,16 @@ extern int zread(void *, char *, int);
 extern int zwrite(void *, const char *, int);
 extern int z_close(void *, struct z_info *, const char *, struct stat *);
 
-
 extern void *gz_ropen(int, char *, int);
 extern void *gz_wopen(int, char *, int, u_int32_t);
 extern int gz_read(void *, char *, int);
 extern int gz_write(void *, const char *, int);
 extern int gz_close(void *, struct z_info *, const char *, struct stat *);
 extern int gz_flush(void *, int);
+
+extern void *zip_ropen(int, char *, int);
+extern int zip_read(void *, char *, int);
+extern int zip_close(void *, struct z_info *, const char *, struct stat *);
 
 extern void *null_ropen(int, char *, int);
 extern void *null_wopen(int, char *, int, u_int32_t);
Index: usr.bin/compress/gzip.1
===
RCS file: /cvs/src/usr.bin/compress/gzip.1,v
retrieving revision 1.15
diff -u -p -u -r1.15 gzip.1
--- usr.bin/compress/gzip.1 14 Mar 2022 21:52:08 -  1.15
+++ usr.bin/compress/gzip.1 14 Oct 2022 00:04:57 -
@@ -83,10 +83,11 @@ utility restores compressed files to the
 files by removing the extension (or by using the stored name if the
 .Fl N
 flag is specified).
-It has the ability to restore files compressed by both
-.Nm
+It has the ability to restore files compressed by
+.Nm ,
+.Xr compress 1
 and
-.Xr compress 1 ,
+.Xr zip 1 ,
 recognising the following extensions:
 .Dq .Z ,
 .Dq -Z ,
@@ -99,14 +100,23 @@ recognising the following extensions:
 .Dq _tgz ,
 .Dq .taz ,
 .Dq -taz ,
+.Dq _taz ,
+.Dq .zip ,
+.Dq -zip
 and
-.Dq _taz .
+.Dq _zip .
 Extensions ending in
 .Dq tgz
 and
 .Dq taz
 are not removed when decompressing, instead they are converted to
 .Dq tar .
+Files in zip format are only supported if they contain a single member
+compressed with either the
+.Em deflate
+or
+.Em store
+(uncompressed) method.
 .Pp
 The
 .Nm gzcat
Index: usr.bin/compress/main.c
===
RCS file: /cvs/src/usr.bin/compress/main.c,v
retrieving revision 1.101
diff -u -p -u -r1.101 main.c
--- usr.bin/compress/main.c 29 Aug 2022 19:42:01 -  1.101
+++ usr.bin/compress/main.c 14 Oct 2022 00:31:14 -
@@ -102,6 +102,20 @@ const struct compressor {
zwrite,
z_close
},
+#define M_UNZIP (_table[2])
+   {
+   "unzip",
+   ".zip",
+   "PK",
+   NULL,
+   "cfhkLlNno:qrtVv",
+   "fhqr",
+   zip_ropen,
+   zip_read,
+   NULL,
+ 

Re: gunzip: support .zip files with a single member

2022-10-13 Thread Todd C . Miller
On Fri, 14 Oct 2022 10:26:33 +1100, Jonathan Gray wrote:

> I can't think of another reason for the single file limit.  It must be.
>
> With most of the changes under SMALL or not built, ramdisks still fit?

It should, none of the new code is compiled for the ramdisk version.

 - todd



Re: gunzip: support .zip files with a single member

2022-10-13 Thread Todd C . Miller
On Fri, 14 Oct 2022 09:41:18 +1100, Jonathan Gray wrote:

> The extracted file has the name of the zip archive without '.zip'
> instead of the name of the file in the zip archive.
>
> Is that the behaviour of GNU gunzip?  It isn't what I expected.

Yes, that is what GNU zip does too.  If you use the -N flag gunzip
will use the stored and (and mtime).

 - todd



gunzip: support .zip files with a single member

2022-10-13 Thread Todd C . Miller
 if (verbose >= 0) {
+   warnx("more than one entry in %s: %s", in,
+   cat ? "ignoring the rest" : "unchanged");
+   }
+   error = WARNING;
+   } else {
+   if (verbose >= 0)
+   warn("%s", in);
+   error = FAILURE;
+   }
}
if (storename && !cat) {
if (info.mtime != 0) {
@@ -739,7 +760,7 @@ dodecompress(const char *in, char *out, 
} else
storename = 0;  /* no timestamp to restore */
}
-   if (error == SUCCESS)
+   if (error != FAILURE)
setfile(out, ofd, sb);
 
if (ofd != -1 && close(ofd)) {
@@ -748,7 +769,7 @@ dodecompress(const char *in, char *out, 
error = FAILURE;
}
 
-   if (!error) {
+   if (error != FAILURE) {
if (list) {
if (info.mtime == 0)
info.mtime = (u_int32_t)sb->st_mtime;
@@ -760,7 +781,7 @@ dodecompress(const char *in, char *out, 
}
 
/* On error, clean up the file we created but preserve errno. */
-   if (error && oreg)
+   if (error == FAILURE && oreg)
unlink(out);
 
return (error);
@@ -830,7 +851,7 @@ check_suffix(const char *infile)
 {
int i;
char *suf, *sep, *separators = ".-_";
-   static char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", NULL };
+   static char *suffixes[] = { "Z", "gz", "z", "tgz", "taz", "zip", NULL };
 
for (sep = separators; *sep != '\0'; sep++) {
if ((suf = strrchr(infile, *sep)) == NULL)
Index: usr.bin/compress/zipopen.c
=======
RCS file: usr.bin/compress/zipopen.c
diff -N usr.bin/compress/zipopen.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.bin/compress/zipopen.c  13 Oct 2022 20:06:33 -
@@ -0,0 +1,447 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2022 Todd C. Miller 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "compress.h"
+
+#define MINIMUM(a, b)  (((a) < (b)) ? (a) : (b))
+
+/* Signatures for zip file headers we use. */
+#define ZIPMAG 0x4b50  /* first two bytes of the zip signature */
+#define LOCREM 0x0403  /* remaining two bytes in zip signature */
+#define LOCSIG 0x04034b50  /* local file header signature */
+#define EXTSIG 0x08074b50  /* extended local header signature */
+
+/* Header sizes. */
+#define LOCHDR 30  /* size of local header, including signature */
+#define EXTHDR 16  /* size of extended local header, inc sig */
+
+/* General purpose flag bits. */
+#define CRPFLG 1   /* flag bit for encrypted entry */
+#define EXTFLG 8   /* flag bit for extended local header */
+
+/* Extra field definitions */
+#defineEF_ZIP640x0001  /* zip64 support */
+#defineEF_TIME 0x5455  /* mtime, atime, ctime in UTC ("UT") */
+#define EF_IZUNIX  0x5855  /* UNIX extra field ID ("UX") */
+
+#define Z_STORED 0 /* Stored uncompressed in .zip */
+
+struct zip_state {
+   z_stream z_stream;  /* libz stream */
+   uint8_t  z_buf[Z_BUFSIZE]; /* I/O buffer */
+   uint8_t  z_eof; /* set if end of input file */
+   uint8_t  z_zip64;   /* 64-bit file sizes */
+   uint16_t z_method;  /* Z_DEFLATE or Z_STORED */
+   uint16_t z_flags;   /* general purpose flags */
+   int  z_fd;  /* zip file descriptor */
+   uint32_t z_time;/* timestamp (mtime) */
+   uint32_t z_crc; /* crc32 of uncompressed data */
+   uint32_t z_ocrc;/* crc32 of uncompressed data (from header) */
+   uint32_t z_hlen;/* length of the zip header */
+   uint64_t z_ulen;/* uncompresse

Re: ps.1: control terminal -> controlling terminal

2022-10-13 Thread Todd C . Miller
On Thu, 13 Oct 2022 14:21:11 +0100, Jason McIntyre wrote:

> hi. i'm not super up on the terminology here, but i do see we still have
> other pages that talk about "control terminal". if any developer wants
> to signal a clear desire to make such changes we can do that.

The current term is "controlling terminal".  I would support a diff
to update this in all the man pages.

 - todd



Re: sparc64: ofwboot: no incremental builds due to broken libsa/libz dep

2022-10-11 Thread Todd C . Miller
On Wed, 12 Oct 2022 03:01:04 +0400, Klemens Nanni wrote:

> sparc64 also has its own under stand/,
> or do you mean that the alpha one is worse than the sparc64?

Oh yes, the alpha one is needlessly complicated.  I suppose this
is not surprising considering the source.

 - todd



Re: sparc64: ofwboot: no incremental builds due to broken libsa/libz dep

2022-10-11 Thread Todd C . Miller
This problem is not confined to sparc64 is it?  At least macppc
seems to have the same issue.  Some, like amd64 and i386, cheat and
just pull in the 4 source files from the libz directory.

It looks like alpha has its own libz and libsa directories which
seems even worse.

 - todd



Re: ksh: errexit executes ERR trap twice

2022-10-11 Thread Todd C . Miller
On Mon, 10 Oct 2022 20:58:29 -, Klemens Nanni wrote:

> The ERR trap is supposed to be run once, regardless of errexit:
>
>   $ ksh -c 'trap "echo ERR" ERR; false'
>   ERR
>   $ ksh -c 'trap "echo ERR" ERR; false' -e
>   ERR
>   ERR
>
> This duplication is a regression of the following bin/ksh/main.c commit:
>
>   revision 1.52
>   date: 2013/06/15 17:25:19;  author: millert;  state: Exp;  lines: +5 -1
> ;
>   Run any pending traps before calling the EXIT or ERR traps when -e
>   is set.  Fixes a bug where we would not run the signal trap if,
>   for example, ^C was pressed and -e was set.  OK espie@
>
> Revert it and add a new test, matching bash(1) behaviour:
>
>   $ ./obj/ksh -c 'trap "echo ERR" ERR; false'
>   ERR
>   $ ./obj/ksh -c 'trap "echo ERR" ERR; false' -e
>   ERR
>
> After that, fix signal handlers (e.g. SIGINT/^C traps) properly.

OK.

 - todd



Re: ksh: trigger ERR trap on permanent I/O redirection failure

2022-10-08 Thread Todd C . Miller
On Sat, 08 Oct 2022 16:01:18 -, Klemens Nanni wrote:

> Account for this to make permanent redirection failure trigger the ERR
> trap:
>
>   $ ./obj/ksh -c 'trap "echo ERR" ERR ; exec >/'
>   ksh: cannot create /: Is a directory
>   ERR
>
> Also add three new regress cases covering this;  others keep passing.
>
> I haven't put this through a bulk build or any other broader testing
> besides ksh regress and the actual script I was working on (which now
> behaves as expected).

That looks correct to me.  I wouldn't expect this to cause portability
issues since bash and zsh have the same behavior as your diff.

 - todd



Re: install.sub: Replace temporary file with variable

2022-10-04 Thread Todd C . Miller
On Tue, 04 Oct 2022 17:58:15 -, Klemens Nanni wrote:

> On Tue, Sep 27, 2022 at 09:32:15AM -0600, Todd C. Miller wrote:
> > On Tue, 27 Sep 2022 11:28:59 -0400, Josiah Frentsos wrote:
> > 
> > > From ksh(1):
> > >
> > > [[ expression ]]
> > > Similar to the test and [ ... ] commands (described later), w
> ith
> > > the following exceptions:
> > >
> > >   o   Field splitting and file name generation are not
> > >   performed on arguments.
> > 
> > Ah, right.  I don't always remember the rules for those new-fangled
> > double-bracket expressions ;-)
>
> Right, omitting quotes inside double brackets is commen style in base.

OK.

 - todd



Re: install.sub: sh is not make, use newlines

2022-10-04 Thread Todd C . Miller
On Tue, 04 Oct 2022 18:17:02 -, Klemens Nanni wrote:

> On Tue, Sep 20, 2022 at 11:19:38AM +, Klemens Nanni wrote:
> > sh(1) happily accepts newlines inside double quotes just like in the
> > script itself:
> > 
> > $ sh -c "echo foo
> > > echo bar"
> > foo
> > bar
> > 
> > So no need to squash things into a single line as is required in make(1)
> > files.
> > 
> > OK? (for after release)
>
> Ping.

OK.

 - todd



Re: tftpd: add -R for read-only mode/reduced pledges

2022-10-04 Thread Todd C . Miller
On Tue, 04 Oct 2022 09:24:04 -, Klemens Nanni wrote:

> > we were read-only believers a long time ago, and it seems the world has
> > caught up to our way of thinking so yes maybe it is time to make it an
> > option you must specify.
>
> I like the idea, then -c should logically imply -w.

Looks great to me.  Most tftp usage these days is for reading so
read-only by default makes sense.

 - todd



Re: tzset(3): update man page to reality

2022-10-03 Thread Todd C . Miller
On Mon, 03 Oct 2022 13:27:05 -0600, "Todd C. Miller" wrote:

> We did not document tzname, timezone or daylight and the rules
> regarding pathnames was not entirely clear.
>
> I think it is worth mentioning that unless your program calls
> chroot(2), you probably don't need to call tzset(3).
>
> Opinions?

Now including examples of the pathname format.

 - todd

Index: lib/libc/time/tzset.3
===
RCS file: /cvs/src/lib/libc/time/tzset.3,v
retrieving revision 1.25
diff -u -p -u -r1.25 tzset.3
--- lib/libc/time/tzset.3   23 Sep 2022 17:29:22 -  1.25
+++ lib/libc/time/tzset.3   3 Oct 2022 19:32:05 -
@@ -8,62 +8,103 @@
 .Nd initialize time conversion information
 .Sh SYNOPSIS
 .In time.h
+.Vt extern char *tzname[2];
+.Vt extern long  timezone;
+.Vt extern long  daylight;
 .Ft void
 .Fn tzset "void"
 .Ft void
 .Fn tzsetwall "void"
 .Sh DESCRIPTION
+The
 .Fn tzset
-uses the value of the environment variable
+function uses the value of the environment variable
 .Ev TZ
-to set time conversion information used by
+to set the time conversion information used by
 .Xr localtime 3 .
-If
-.Ev TZ
-does not appear in the environment,
-or if the calling process has changed its user or group ID,
-the best available approximation to local wall clock time, as specified
-by the
-.Xr tzfile 5
-format file
-.Pa /etc/localtime ,
-is used by
+It also sets the following external variables:
+.Bl -tag -width "tzname[2]"
+.It Vt tzname[2]
+the designations for standard and daylight saving time, see the description of
+.Ar std No and Ar dst
+below
+.It Vt timezone
+the number of seconds West of UTC
+.It Vt daylight
+0 if the time zone has never observed daylight saving time, otherwise
+non-zero
+.El
+.Pp
+Most programs do not need to call
+.Fn tzset
+directly, it will be called automatically as needed by the functions
+described in
 .Xr localtime 3 .
+Privileged processes that use
+.Xr chroot 2
+may wish to call
+.Fn tzset
+to initialize the time conversion information before changing to
+a restricted root directory that does not include time conversion
+data files.
 .Pp
 If
 .Ev TZ
-appears in the environment but its value is a null string,
-Coordinated Universal Time (UTC) is used (without leap second
-correction).
+does not appear in the environment, or if the calling process has
+changed its user or group ID, the system time zone file,
+.Pa /etc/localtime ,
+is used.
 .Pp
 If
 .Ev TZ
-appears in the environment and its value begins with a colon,
-it is used as the pathname of a file
-from which to read the time conversion information.
+appears in the environment it may be one of two formats:
+.Bl -bullet
+.It
+the pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
+optionally prefixed with a colon
+.Pq Ql \&: ,
+such as
+.Dq :America/Denver
+or
+.Dq Europe/Berlin .
+.It
+a string that directly specifies the time conversion information
+(see below) which may not begin with a colon
+.Pq Ql \&:
+.El
 .Pp
 If
 .Ev TZ
 appears in the environment and its value does not begin with a colon,
 it is first used as the
-pathname of a file from which to read the time conversion information,
+pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
 and, if that file cannot be read, is used directly as a specification of
 the time conversion information.
+A value beginning with a colon
+.Pq Ql \&:
+is always treated as a pathname.
+.Pp
+If
+.Ev TZ
+it set to the empty string, Coordinated Universal Time (UTC) is
+used (without leap second correction).
 .Pp
 When
 .Ev TZ
-is used as a pathname, it must be relative to the system time
+is used as a pathname, it must either be a path relative to the system time
 conversion information directory,
-.Pa /usr/share/zoneinfo .
-If
-.Ev TZ
-begins with a
-.Ql /
-or contains
+.Pa /usr/share/zoneinfo
+or an absolute path that begins with
+.Pa /usr/share/zoneinfo/ .
+Other absolute paths, or paths that contain
 .Ql \&../ ,
-it is ignored and the system local time zone file,
+will be ignored and the system local time zone file,
 .Pa /etc/localtime ,
-is used instead.
+will be used instead.
 The file must be in the format specified in
 .Xr tzfile 5 .
 .Pp
@@ -74,7 +115,7 @@ it must have the following syntax (witho
 .Ar std
 and
 .Ar offset ) :
-.Bd -ragged -offset indent
+.Bd -offset indent
 .Ar std
 .Sm off
 .Ar offset
@@ -88,23 +129,23 @@ Where:
 .It Ar std No and Ar dst
 Three or more bytes that are the designation for the standard
 .Pq Ar std
-or summer
+or the daylight saving
 .Pq Ar dst
 time zone.
 Only
 .Ar std
 is required; if
 .Ar dst
-is missing, then summer time does not apply in this locale.
+is missing, then daylight saving time does not apply in this locale.
 Upper and lowercase letters are explicitly allowed.
 Any characters except a leading colon
-.Pq Sq 

tzset(3): update man page to reality

2022-10-03 Thread Todd C . Miller
We did not document tzname, timezone or daylight and the rules
regarding pathnames was not entirely clear.

I think it is worth mentioning that unless your program calls
chroot(2), you probably don't need to call tzset(3).

Opinions?

 - todd

Index: lib/libc/time/tzset.3
===
RCS file: /cvs/src/lib/libc/time/tzset.3,v
retrieving revision 1.25
diff -u -p -u -r1.25 tzset.3
--- lib/libc/time/tzset.3   23 Sep 2022 17:29:22 -  1.25
+++ lib/libc/time/tzset.3   3 Oct 2022 19:24:02 -
@@ -8,62 +8,99 @@
 .Nd initialize time conversion information
 .Sh SYNOPSIS
 .In time.h
+.Vt extern char *tzname[2];
+.Vt extern long  timezone;
+.Vt extern long  daylight;
 .Ft void
 .Fn tzset "void"
 .Ft void
 .Fn tzsetwall "void"
 .Sh DESCRIPTION
+The
 .Fn tzset
-uses the value of the environment variable
+function uses the value of the environment variable
 .Ev TZ
-to set time conversion information used by
+to set the time conversion information used by
 .Xr localtime 3 .
-If
-.Ev TZ
-does not appear in the environment,
-or if the calling process has changed its user or group ID,
-the best available approximation to local wall clock time, as specified
-by the
-.Xr tzfile 5
-format file
-.Pa /etc/localtime ,
-is used by
+It also sets the following external variables:
+.Bl -tag -width "tzname[2]"
+.It Vt tzname[2]
+the designations for standard and daylight saving time, see the description of
+.Ar std No and Ar dst
+below
+.It Vt timezone
+the number of seconds West of UTC
+.It Vt daylight
+0 if the time zone has never observed daylight saving time, otherwise
+non-zero
+.El
+.Pp
+Most programs do not need to call
+.Fn tzset
+directly, it will be called automatically as needed by the functions
+described in
 .Xr localtime 3 .
+Privileged processes that use
+.Xr chroot 2
+may wish to call
+.Fn tzset
+to initialize the time conversion information before changing to
+a restricted root directory that does not include time conversion
+data files.
 .Pp
 If
 .Ev TZ
-appears in the environment but its value is a null string,
-Coordinated Universal Time (UTC) is used (without leap second
-correction).
+does not appear in the environment, or if the calling process has
+changed its user or group ID, the system time zone file,
+.Pa /etc/localtime ,
+is used.
 .Pp
 If
 .Ev TZ
-appears in the environment and its value begins with a colon,
-it is used as the pathname of a file
-from which to read the time conversion information.
+appears in the environment it may be one of two formats:
+.Bl -bullet
+.It
+the pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
+optionally prefixed with a colon
+.Pq Ql \&:
+.It
+a string containing the time conversion information (see below)
+which may not begin with a colon
+.Pq Ql \&:
+.El
 .Pp
 If
 .Ev TZ
 appears in the environment and its value does not begin with a colon,
 it is first used as the
-pathname of a file from which to read the time conversion information,
+pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
 and, if that file cannot be read, is used directly as a specification of
 the time conversion information.
+A value beginning with a colon
+.Pq Ql \&:
+is always treated as a pathname.
+.Pp
+If
+.Ev TZ
+it set to the empty string, Coordinated Universal Time (UTC) is
+used (without leap second correction).
 .Pp
 When
 .Ev TZ
-is used as a pathname, it must be relative to the system time
+is used as a pathname, it must either be a path relative to the system time
 conversion information directory,
-.Pa /usr/share/zoneinfo .
-If
-.Ev TZ
-begins with a
-.Ql /
-or contains
+.Pa /usr/share/zoneinfo
+or an absolute path that begins with
+.Pa /usr/share/zoneinfo/ .
+Other absolute paths, or paths that contain
 .Ql \&../ ,
-it is ignored and the system local time zone file,
+will be ignored and the system local time zone file,
 .Pa /etc/localtime ,
-is used instead.
+will be used instead.
 The file must be in the format specified in
 .Xr tzfile 5 .
 .Pp
@@ -74,7 +111,7 @@ it must have the following syntax (witho
 .Ar std
 and
 .Ar offset ) :
-.Bd -ragged -offset indent
+.Bd -offset indent
 .Ar std
 .Sm off
 .Ar offset
@@ -88,23 +125,23 @@ Where:
 .It Ar std No and Ar dst
 Three or more bytes that are the designation for the standard
 .Pq Ar std
-or summer
+or the daylight saving
 .Pq Ar dst
 time zone.
 Only
 .Ar std
 is required; if
 .Ar dst
-is missing, then summer time does not apply in this locale.
+is missing, then daylight saving time does not apply in this locale.
 Upper and lowercase letters are explicitly allowed.
 Any characters except a leading colon
-.Pq Sq \&: ,
+.Pq Ql \&: ,
 digits, comma
-.Pq Sq \&, ,
+.Pq Ql \&, ,
 minus
-.Pq Sq \&- ,
+.Pq Ql \&- ,
 plus
-.Pq Sq \&+ ,
+.Pq Ql \&+ ,
 and ASCII NUL are allowed.
 .It Ar offset
 Indicates the value one must add to the local time to arrive at
@@ -131,7 +168,7 @@ If no
 .Ar 

Re: rarpd: unveil /tftpboot only if needed

2022-10-02 Thread Todd C . Miller
On Sun, 02 Oct 2022 12:33:21 -, Klemens Nanni wrote:

>  -t  Only honour a request if the server (the host that rarpd is
>  running on) can "boot" the target; that is, if a file or
>  directory called /tftpboot/ipaddr exists, where ipaddr is the
>  target IP address expressed in uppercase hexadecimal (only the
>  first 8 characters of filenames are checked).
>
> Unless -t is used, this directory is not accessed in any way;  TFTP_DIR
> is used once in rarp_bootable() which gets called once:
>
>   if (tflag == 0 || rarp_bootable(htonl(target_ipaddr)))
>   rarp_reply(ii, ia, ep, target_ipaddr, hp);  

OK millert@

 - todd



Re: wc(1): add -L flag to write length of longest line

2022-09-30 Thread Todd C . Miller
On Thu, 29 Sep 2022 23:30:54 -0400, Daniel Dickman wrote:

> > On Sep 29, 2022, at 8:24 PM, Joerg Sonnenberger  wrote:
> > 
> > On Thu, Sep 29, 2022 at 08:39:16PM +1000, Jonathan Gray wrote:
> >> wc counts items in files.  Finding the longest item indeed sounds
> >> like a task better suited to awk.
>
> Doesn’t gnu wc show that tabs have length 8 rather than length 1?

Yes.

> Do the other wc implementations differ?

FreeBSD and NetBSD "wc -L" counts it as a single character.

 - todd



Re: install.sub: Replace temporary file with variable

2022-09-27 Thread Todd C . Miller
On Tue, 27 Sep 2022 11:28:59 -0400, Josiah Frentsos wrote:

> From ksh(1):
>
> [[ expression ]]
> Similar to the test and [ ... ] commands (described later), with
> the following exceptions:
>
>   o   Field splitting and file name generation are not
>   performed on arguments.

Ah, right.  I don't always remember the rules for those new-fangled
double-bracket expressions ;-)

 - todd



Re: install.sub: Replace temporary file with variable

2022-09-27 Thread Todd C . Miller
On Tue, 27 Sep 2022 13:49:10 -, Klemens Nanni wrote:

> The double quotes retain the newlines;  without them column(1) would
> print a single line (possibly longer than 80 chars).

Don't you also need double quotes around $_CKPATCH:

if [[ -n $_CKPATCH ]]; then

in case it contains multiple words?

 - todd



Re: sysupgrade - Reading from socket: Undefined error: 0

2022-09-20 Thread Todd C . Miller
On Tue, 20 Sep 2022 08:50:10 +0200, Florian Obser wrote:

> Is this somehow coming from the non-blocking connect diff? I can't spot
> it though...

I don't think so, the ktrace shows that read(2) is returning 0 long
after connect.  If the socket was left in non-blocking mode I could
see that causing problems but the file flags get restored.

 - todd



Re: sysupgrade - timezone

2022-09-19 Thread Todd C . Miller
There was a bad diff in that snapshot that caused tzset() to ignore
/etc/localtime.

 - todd



Re: sysupgrade - timezone

2022-09-19 Thread Todd C . Miller
On Mon, 19 Sep 2022 23:06:13 +0200, Hrvoje Popovski wrote:

> after sysupgrade I'm having GMT
>
> OpenBSD 7.2 (GENERIC.MP) #736: Mon Sep 19 17:56:55 GMT 2022
> r620-1# date
> Mon Sep 19 21:01:14 GMT 2022
>
> r620-1# ls -apl /etc/localtime
> lrwxr-xr-x  1 root  wheel  33 Feb 10  2022 /etc/localtime ->
> /usr/share/zoneinfo/Europe/Zagreb
>
> I didn't upgrade r420-1 yet, but other boxes are upgraded to latest snapshot

Can you check the permissions on /usr/share/zoneinfo/Europe/Zagreb?
If that file is not readable you will end up with GMT.

If it looks OK, what does:

TZ=Europe/Zagreb date

produce?

 - todd



Re: ksh.1: == in [[ does pattern matching as well

2022-09-13 Thread Todd C . Miller
OK millert@ for the revised diff.

 - todd



Re: ksh.1: == in [[ does pattern matching as well

2022-09-13 Thread Todd C . Miller
On Tue, 13 Sep 2022 19:26:47 -, Klemens Nanni wrote:

> install.sub uses [[ foo == f*o ]] extensively, yet ksh(1) only documents
> pattern matching for the = and != operators.

Think of the wasted bytes in install.sub!

> Just like with [, = and == behave the same in [[ last time I checked.
>
>   $ [[ foo = f*o ]] && echo match
>   match
>   $ [[ foo == f*o ]] && echo match
>   match
>
> Feedback? OK?

This is correct, though I'd prefer if the single "=" came first to
match the order given in the operators section.  E.g.

The second operand of the
.Sq = ,
.Sq ==
and
.Sq !=
expressions are patterns (e.g. the comparison

 - todd



Re: ftp(1) connection timeouts and hostnames with multiple addresses

2022-09-13 Thread Todd C . Miller
On Tue, 13 Sep 2022 20:21:58 +0100, Stuart Henderson wrote:

> Oh great, that works very nicely for this use case, thank you. Connecting
> via a proxy also still works as I'd expect. I'm basically OK with that
> diff though I'd like to test the installer (I have some mkb/mkr running
> now).

Great.  I've only done minimal testing (and no installer tests).

> Then we could either have fw_update call ftp with something like "-w 12",
> or automatically lower ftp(1)'s default as with the diff in
> https://marc.info/?l=openbsd-tech=165736755609602=2

I'd be OK with that too but it should be a follow-on commit.

 - todd



Re: ftp(1) connection timeouts and hostnames with multiple addresses

2022-09-13 Thread Todd C . Miller
On Sat, 09 Jul 2022 12:53:17 +0100, Stuart Henderson wrote:

> I'm trying to teach ftp(1) to do something like gui web browsers do
> and reduce the HTTP/HTTPS connection timeout from the default (75 seconds)
> if there are multiple addresses behind a hostname.
>
> There's an existing connection timeout mechanism that I thought it
> might make sense to reuse...
>
>  -w seconds
>  For URL format connections to HTTP/HTTPS servers, abort a slow
>  connection after seconds.

Here's a diff to implement timed_connect().  It replaces the alarm
used for slow connections with non-blocking connect(2) and ppoll(2).
I've also replaced the other connect(2) + connect_wait() calls with
timed_connect() so the -w option now works for more that just http.

 - todd

Index: usr.bin/ftp/extern.h
===
RCS file: /cvs/src/usr.bin/ftp/extern.h,v
retrieving revision 1.52
diff -u -p -u -r1.52 extern.h
--- usr.bin/ftp/extern.h2 Feb 2021 12:58:42 -   1.52
+++ usr.bin/ftp/extern.h13 Sep 2022 16:43:30 -
@@ -62,6 +62,7 @@
  */
 
 #include 
+#include 
 
 void   abort_remote(FILE *);
 void   abortpt(int);
@@ -75,7 +76,6 @@ void  cmdabort(int);
 void   cmdscanner(int);
 intcommand(const char *, ...);
 intconfirm(const char *, const char *);
-intconnect_wait(int);
 FILE   *dataconn(const char *);
 intforegroundproc(void);
 intfileindir(const char *, const char *);
@@ -109,6 +109,7 @@ voidsethash(int, char **);
 void   setpeer(int, char **);
 void   setttywidth(int);
 char   *slurpstring(void);
+inttimed_connect(int s, const struct sockaddr *, socklen_t, int);
 
 __dead voidusage(void);
 
Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.209
diff -u -p -u -r1.209 fetch.c
--- usr.bin/ftp/fetch.c 8 Sep 2022 11:12:44 -   1.209
+++ usr.bin/ftp/fetch.c 13 Sep 2022 16:40:00 -
@@ -173,14 +173,6 @@ url_encode(const char *path)
return (epath);
 }
 
-/* ARGSUSED */
-static void
-tooslow(int signo)
-{
-   dprintf(STDERR_FILENO, "%s: connect taking too long\n", __progname);
-   _exit(2);
-}
-
 /*
  * Copy a local file (used by the OpenBSD installer).
  * Returns -1 on failure, 0 on success
@@ -604,14 +596,8 @@ noslash:
}
 #endif /* !SMALL */
 
-   if (connect_timeout) {
-   (void)signal(SIGALRM, tooslow);
-   alarmtimer(connect_timeout);
-   }
-
-   for (error = connect(fd, res->ai_addr, res->ai_addrlen);
-   error != 0 && errno == EINTR; error = connect_wait(fd))
-   continue;
+   error = timed_connect(fd, res->ai_addr, res->ai_addrlen,
+   connect_timeout);
if (error != 0) {
save_errno = errno;
close(fd);
@@ -700,11 +686,6 @@ noslash:
}
 #endif
 
-   if (connect_timeout) {
-   signal(SIGALRM, SIG_DFL);
-   alarmtimer(0);
-   }
-
/*
 * Construct and send the request. Proxy requests don't want leading /.
 */
@@ -1242,7 +1223,6 @@ aborthttp(int signo)
 {
const char errmsg[] = "\nfetch aborted.\n";
 
-   alarmtimer(0);
write(fileno(ttyout), errmsg, sizeof(errmsg) - 1);
longjmp(httpabort, 1);
 }
Index: usr.bin/ftp/ftp.1
===
RCS file: /cvs/src/usr.bin/ftp/ftp.1,v
retrieving revision 1.123
diff -u -p -u -r1.123 ftp.1
--- usr.bin/ftp/ftp.1   27 Mar 2022 20:09:12 -  1.123
+++ usr.bin/ftp/ftp.1   13 Sep 2022 16:49:38 -
@@ -320,9 +320,9 @@ Forces
 to show all responses from the remote server, as well
 as report on data transfer statistics.
 .It Fl w Ar seconds
-For URL format connections to HTTP/HTTPS servers, abort a
-slow connection after
-.Ar seconds .
+Wait for
+.Ar seconds
+for the remote server to connect before giving up.
 .El
 .Pp
 The host with which
Index: usr.bin/ftp/ftp.c
===
RCS file: /cvs/src/usr.bin/ftp/ftp.c,v
retrieving revision 1.107
diff -u -p -u -r1.107 ftp.c
--- usr.bin/ftp/ftp.c   18 Nov 2019 04:37:35 -  1.107
+++ usr.bin/ftp/ftp.c   13 Sep 2022 16:43:03 -
@@ -212,9 +212,8 @@ hookup(char *host, char *port)
}
}
 #endif /* !SMALL */
-   for (error = connect(s, res->ai_addr, res->ai_addrlen);
-   error != 0 && errno == EINTR; error = connect_wait(s))
-   continue;
+   error = timed_connect(s, res->ai_addr, res->ai_addrlen,
+   connect_timeout);
if (error != 0) {
/* this "if" clause is to prevent print warning twice */
if 

Re: top(1): remove last vestiges of "last pid"

2022-09-09 Thread Todd C . Miller
On Fri, 09 Sep 2022 20:19:26 -0500, Scott Cheloha wrote:

> millert@ removed most of the "last pid" pieces from top(1) in 1997:
>
> http://cvsweb.openbsd.org/src/usr.bin/top/machine.c?rev=1.7=text
> /x-cvsweb-markup
>
> Some small bits remain, though.  Can we remove the rest?

Sure.  OK millert@

 - todd



Re: init(8): signal handler boolean needs to be "volatile"

2022-09-09 Thread Todd C . Miller
On Fri, 09 Sep 2022 14:05:46 -0500, Scott Cheloha wrote:

> The variable "clang" is modified from a signal handler.  It should be
> of type sig_atomic_t and it needs to be volatile.

Right.  OK millert@

 - todd



Re: installboot: reflect script failure in exit code

2022-09-08 Thread Todd C . Miller
On Thu, 08 Sep 2022 20:04:58 -, Klemens Nanni wrote:

> Here's the full diff to fsck and newfs failure on all architectures.
>
> This is a regular programming issue around system(3) that has nothing to
> do with bootloaders or installboot per se.
>
> I'd be great to get this in to make further progress, especially on
> softraid support for the -p option.  The less diffs I have to juggle on
> multiple test machines the better.

This seems like a reasonable approach to me.  It will also catch
news/fsck dying from a signal since the shell exits with a value
of 128 + signal_number in that case.

 - todd



Re: add sendmmsg and recvmmsg systemcalls

2022-08-30 Thread Todd C . Miller
On Wed, 31 Aug 2022 00:19:20 +0200, Moritz Buhl wrote:

> On Tue, Aug 30, 2022 at 10:59:43PM +0200, Claudio Jeker wrote:
> > And nsd in base. It seems unbound does not use recvmmsg. 
>
> After 'make -f Makefile.bsd-wrapper config' recvmmsg is picked up.
> The config compile test currently defines NONBLOCKING_IS_BROKEN
> because of a missing include.  Then vlen for recvmmsg would always
> be 1.
>
> checking for struct mmsghdr... yes
> checking for recvmmsg... yes
> checking for sendmmsg... no
> ...
> checking if nonblocking sockets work... yes
>
> If anybody knows how to make nsd call nsd_recvmmsg this would
> make for some nice testing.

Does this also fix the configure test?  If so, we can submit it
upstream.

 - todd

Index: acx_nlnetlabs.m4
===
RCS file: /cvs/src/usr.sbin/nsd/acx_nlnetlabs.m4,v
retrieving revision 1.7
diff -u -p -u -r1.7 acx_nlnetlabs.m4
--- acx_nlnetlabs.m424 Oct 2021 12:14:18 -  1.7
+++ acx_nlnetlabs.m430 Aug 2022 22:31:48 -
@@ -963,6 +963,9 @@ AC_LANG_SOURCE([[
 #ifdef HAVE_SYS_TYPES_H
 #include 
 #endif
+#ifdef HAVE_SYS_SELECT_H
+#include 
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 #include 
 #endif
Index: configure
===
RCS file: /cvs/src/usr.sbin/nsd/configure,v
retrieving revision 1.56
diff -u -p -u -r1.56 configure
--- configure   30 Jun 2022 10:49:39 -  1.56
+++ configure   30 Aug 2022 22:32:08 -
@@ -6593,6 +6593,9 @@ else
 #ifdef HAVE_SYS_TYPES_H
 #include 
 #endif
+#ifdef HAVE_SYS_SELECT_H
+#include 
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 #include 
 #endif



Re: libutil: opendev: require block/character devices

2022-08-25 Thread Todd C . Miller
On Thu, 25 Aug 2022 11:50:31 -, Klemens Nanni wrote:

> And this should use the ternary operator, as this would still succeed
> if path is a character device even though OPENDEV_BLCK was passed.

Sure.  OK millert@

 - todd



Re: libutil: opendev: require block/character devices

2022-08-25 Thread Todd C . Miller
On Thu, 25 Aug 2022 05:36:53 -, Klemens Nanni wrote:

> Ah yes, the failure check does not return early but falls through, so
> all further logic needs to check fd and/or errno (like the isduid() case
> already does).

OK millert@

 - todd



Re: libutil: opendev: require block/character devices

2022-08-24 Thread Todd C . Miller
On Wed, 24 Aug 2022 20:06:00 -, Klemens Nanni wrote:

> Feedback? Am I missing anything?

If fstat(2) fails you should not try to access sb.  Perhaps:

if (((dflags & OPENDEV_BLCK) && ...

should be an "else if (..."

Otherwise looks OK to me.

 - todd



Re: vnconfig: fix usage

2022-08-19 Thread Todd C . Miller
On Fri, 19 Aug 2022 18:47:26 -, Klemens Nanni wrote:

> Can also do just that.
>
> For install media it could be worth it since a single fprintf(3) call
> saves some bits in text, but vnconfig(8) is not on amy install media...

Your original diff is OK with me, sorry if that wasn't clear.

 - todd



Re: vnconfig: zap useless cast

2022-08-19 Thread Todd C . Miller
On Fri, 19 Aug 2022 18:35:26 -, Klemens Nanni wrote:

> opendev(3) takes a const char *, just what getinfo() provides.
>
> I see no point in casting away the const;  no amd64 object change.

OK millert@

 - todd



Re: vnconfig: fix usage

2022-08-19 Thread Todd C . Miller
On Fri, 19 Aug 2022 18:32:12 -, Klemens Nanni wrote:

> The manual has it right about -k and -K being mutually exclusive;
> adapt the internal text.
>
> Merge the printf calls while here.

OK millert@ for making usage match the manual.

 - todd



Re: installboot: clarify how -p only sets up the filesystem

2022-08-18 Thread Todd C . Miller
On Thu, 18 Aug 2022 18:53:41 -, Klemens Nanni wrote:

> root is now initalised before the verbose check so it is independent of
> -v usage and happens after prepare code, indicating that -p does not
> care about -r.

OK millert@

 - todd



Re: installboot: clarify how -p only sets up the filesystem

2022-08-18 Thread Todd C . Miller
On Thu, 18 Aug 2022 11:51:19 -, Klemens Nanni wrote:

> I've checked all usage combination of flags and arguments, the new code
> does what the new synopsis says.

I agree with the general direction but have one concern.  See inline.

 - todd

> Index: installboot.c
> ===
> RCS file: /cvs/src/usr.sbin/installboot/installboot.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 installboot.c
> --- installboot.c 20 Jul 2021 14:51:56 -  1.14
> +++ installboot.c 18 Aug 2022 11:42:43 -
> @@ -31,17 +31,16 @@ int   prepare;
>  int  stages;
>  int  verbose;
>  
> -char *root = "/";
> +char *root;

If you don't initalize root here, a NULL pointer will be used later
when the -v option is not also used.  You could also kill the useless
strdup of optarg when the -r option is used.

>  char *stage1;
>  char *stage2;
>  
>  static __dead void
>  usage(void)
>  {
> - extern char *__progname;
> -
> - fprintf(stderr, "usage: %s [-npv] [-r root] disk [stage1%s]\n",
> - __progname, (stages >= 2) ? " [stage2]" : "");
> + fprintf(stderr, "usage:\t%1$s [-nv] [-r root] disk [stage1%2$s]\n"
> + "\t%1$s [-nv] -p disk\n",
> + getprogname(), (stages >= 2) ? " [stage2]" : "");
>  
>   exit(1);
>  }
> @@ -80,6 +79,8 @@ main(int argc, char **argv)
>  
>   if (argc < 1 || argc > stages + 1)
>   usage();
> + if (prepare && (root != NULL || argc > 1))
> + usage();
>  
>   dev = argv[0];
>   if (argc > 1)
> @@ -87,9 +88,21 @@ main(int argc, char **argv)
>   if (argc > 2)
>   stage2 = argv[2];
>  
> + if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART,
> + )) == -1)
> + err(1, "open: %s", realdev);
> +
> + if (prepare) {
> + md_prepareboot(devfd, realdev);
> + return 0;
> + }
> +
>   /* Prefix stages with root, unless they were user supplied. */
> - if (verbose)
> + if (verbose) {
> + if (root == NULL)
> + root = "/";
>   fprintf(stderr, "Using %s as root\n", root);
> + }
>   if (argc <= 1 && stage1 != NULL) {
>   stage1 = fileprefix(root, stage1);

With your diff root may be NULL when calling fileprefix().

>   if (stage1 == NULL)
> @@ -101,10 +114,6 @@ main(int argc, char **argv)
>   exit(1);
>   }
>  
> - if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART,
> - )) == -1)
> - err(1, "open: %s", realdev);
> -
>  if (verbose) {
>   fprintf(stderr, "%s bootstrap on %s\n",
>   (nowrite ? "would install" : "installing"), realdev);
> @@ -118,11 +127,6 @@ main(int argc, char **argv)
>   }
>  
>   md_loadboot();
> -
> - if (prepare) {
> - md_prepareboot(devfd, realdev);
> - return 0;
> - }
>  
>  #ifdef SOFTRAID
>   sr_installboot(devfd, dev);
>



Re: Remove unneeded kern.nselcoll sysctl

2022-08-14 Thread Todd C . Miller
On Sun, 14 Aug 2022 11:13:35 -, Visa Hankala wrote:

> Remove unneeded kern.nselcoll sysctl.
>
> The last use of this sysctl in base was removed over two weeks ago.
> Debian Code Search does not show any uses of the KERN_NSELCOLL macro.

OK millert@

 - todd



Re: renice(8): don't succeed after 256 errors

2022-08-11 Thread Todd C . Miller
On Thu, 11 Aug 2022 17:55:08 -0500, Scott Cheloha wrote:

> Fix is to just set error instead of incrementing it.

Sure.  OK millert@

 - todd



Re: store pf rules in a tree

2022-08-10 Thread Todd C . Miller
On Wed, 10 Aug 2022 14:38:16 -, Stefan Butz wrote:

> this mail includes a patch to store pf rules in a red-black tree.
> Currently they are stored in a linked list.
> My system configured with 16000 rules takes about 10 minutes
> to print them out using `pfctl -sr`.
> This patch decreases the time to 4 seconds.
> I was not able to measure a time increase for rule insertion.
> Inserting a lot of labels is still very slow.
> This has to be attacked separatly.

You are using the rule number 'nr' as the key for items in the tree.
However, that field can change post-insertion.  Won't that invalidate
the tree order?

See pf_purge_rule() and the DIOCCHANGERULE case in pfioctl()
for examples of what I mean.

 - todd



Re: alpha: remove misaligned access emulation code

2022-08-09 Thread Todd C . Miller
On Tue, 09 Aug 2022 19:39:31 -, Miod Vallat wrote:

> The alpha part contains code in the kernel to handle unaligned memory
> accesses from userland programs, to prevent them from dying in horrible
> SIGBUS.
>
> This made sense in the '90s, but since then people have learned to work
> with strict-alignment architectures, and this code has been less and
> less triggered - in my own experience I don't remember seeing it
> triggered in the last 20 years.
>
> I think it's time to send it to the Attic for a well-deserved
> retirement, and let these ill-behaved userland programs catch the SIGBUS
> they deserve.

Makes sense to me.  There's no reason alpha needs to suport unaligned
memory accesses when we have other strict alignment architectures
that don't do the fixup.

 - todd



Re: fgetln->getline in games/* (Was: Re: quiz(6): fully switch to getline(3))

2022-08-08 Thread Todd C . Miller
Looks fine to me, though the free(answer) before exit(0) in quiz.c
is not needed.  OK millert@

 - todd



Re: patch: change swblk_t type and use it in blist

2022-08-05 Thread Todd C . Miller
On Sat, 06 Aug 2022 02:19:31 +0200, Jeremie Courreges-Anglas wrote:

> This seems fair, but maybe we should just zap the type from sys/types.h and
> define it only in sys/blist.h, as done in DragonflyBSD?

Fine with me.  It is a non-standard type not used by base.

 - todd



Re: dmesg(8): fail if given positional arguments

2022-08-02 Thread Todd C . Miller
On Tue, 02 Aug 2022 11:52:33 -0500, Scott Cheloha wrote:

> dmesg(8) doesn't use any positional arguments.  It's a usage error if
> any are present.

Sure.  Ok millert@

 - todd



Re: echo(1): check for stdio errors

2022-07-30 Thread Todd C . Miller
On Sat, 30 Jul 2022 18:19:02 -0500, Scott Cheloha wrote:

> Bump.  The standard's error cases for fflush(3) are identical to those
> for fclose(3):
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html
>
> Is the fact that our fclose(3) can succeed even if the error flag is
> set a bug?

As far as I can tell, neither fflush() nor fclose() check the status
of the error flag, though they may set it of course.  That is why
I was suggesting an explicit ferror() call at the end.

 - todd



Re: echo(1): check for stdio errors

2022-07-11 Thread Todd C . Miller
On Sun, 10 Jul 2022 20:58:35 -0900, Philip Guenther wrote:

> Three thoughts:
> 1) Since stdio errors are sticky, is there any real advantage to checking
> each call instead of just checking the final fclose()?

Will that really catch all errors?  From what I can tell, fclose(3)
can succeed even if the error flag was set.  The pattern I prefer
is to use a final fflush(3) followed by a call to ferror(3) before
the fclose(3).

 - todd



Re: ftp(1) connection timeouts and hostnames with multiple addresses

2022-07-09 Thread Todd C . Miller
Instead of the existing alarm() mechanism, how about using
timeout_connect() from usr.bin/nc/netcat.c?

 - todd



Re: obsolete dump options syntax

2022-06-02 Thread Todd C . Miller
On Thu, 02 Jun 2022 07:54:02 -0600, "Theo de Raadt" wrote:

> I'm fine with a / check, but it also needs documenting.  While there can't
> we say at least one option must be supplied?

How about this?

 - todd

Index: sbin/dump/dump.8
===
RCS file: /cvs/src/sbin/dump/dump.8,v
retrieving revision 1.54
diff -u -p -u -r1.54 dump.8
--- sbin/dump/dump.819 Dec 2019 09:38:03 -  1.54
+++ sbin/dump/dump.82 Jun 2022 14:39:09 -
@@ -293,6 +293,13 @@ In the latter case, certain restrictions
 is ignored, the only dump level that is supported is
 .Fl 0 ,
 and all of the files must reside on the same filesystem.
+If no options are specified, the first of the
+.Ar files-to-dump
+must contain a
+.Ql /
+character to prevent it from being interpreted as a
+.Bx 4.3
+option string.
 .Pp
 .Nm
 requires operator intervention on these conditions:
Index: sbin/dump/main.c
===
RCS file: /cvs/src/sbin/dump/main.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 main.c
--- sbin/dump/main.c21 Jan 2021 00:16:36 -  1.62
+++ sbin/dump/main.c2 Jun 2022 13:32:15 -
@@ -718,9 +718,9 @@ obsolete(int *argcp, char **argvp[])
argv = *argvp;
argc = *argcp;
 
-   /* Return if no arguments or first argument has leading dash. */
+   /* Return if no args or first argument has leading dash or a slash. */
ap = argv[1];
-   if (argc == 1 || *ap == '-')
+   if (argc == 1 || *ap == '-' || strchr(ap, '/') != NULL)
return;
 
/* Allocate space for new arguments. */



Re: obsolete dump options syntax

2022-06-02 Thread Todd C . Miller
On Thu, 02 Jun 2022 07:43:15 -0600, "Theo de Raadt" wrote:

> Hmm, but consider these cases
>
> dump home
>
> or
>
> mkdir 0af
> dump 0af
>
> or
>
> cd /dev && dump rsd0a

True, those would not be handled but isn't the most common usage
to pass a fully-qualified path or a device name?  The biggest problem
I see is that this would not catch a disk uid being used but I don't
think that is really fixable unless we check the string for a duid
first.

> Don't people always pass at least '0' (to ignore a stored level) and/or
> 'a' (to avoid the volume sizing code), on very large filesystems in
> particular, so it becomes good practice to always pass at least one
> option, so maybe we should just state the requirement is you must pass a
> flag?  Or are there people passing no flags?

I certainly always have, for example "dump 0f ...".
That said, I don't see a downside to avoiding interpreting what is
clearly a pathname as an obsolete argument.

 - todd



Re: obsolete dump options syntax

2022-06-02 Thread Todd C . Miller
On Thu, 02 Jun 2022 14:36:16 +0200, Jan Stary wrote:

> That results in the above. What obsolete options format
> is this trying to accomodate? The manpage doesn't say -
> the options it describes are perfectly getopt()-likable.
> Looking at the CVS log, this was already "obsolete"
> in the original 1995 import. Does anyone still use
> that undescribed obsolete syntax dump "supports"?

Yes, many people do, myself included.  These programs have worked
this way for the past 42 years and you cannot just break that.

However, it may be reasonable to skip parsing in obsolete() if the
first argument contains a '/' since that is cannot match the old
syntax.  FreeBSD just checks for a leading slash.

 - todd

Index: main.c
===
RCS file: /cvs/src/sbin/dump/main.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 main.c
--- main.c  21 Jan 2021 00:16:36 -  1.62
+++ main.c  2 Jun 2022 13:32:15 -
@@ -718,9 +718,9 @@ obsolete(int *argcp, char **argvp[])
argv = *argvp;
argc = *argcp;
 
-   /* Return if no arguments or first argument has leading dash. */
+   /* Return if no args or first argument has leading dash or a slash. */
ap = argv[1];
-   if (argc == 1 || *ap == '-')
+   if (argc == 1 || *ap == '-' || strchr(ap, '/') != NULL)
return;
 
/* Allocate space for new arguments. */



Re: tar extract to stdout

2022-05-26 Thread Todd C . Miller
Our tar's -O flag is only used when creating an archive, it is
unused for extraction.  I'd prefer that we use the same option
letter as GNU tar and bsdtar for this.

 - todd



Re: librthread: validate timespec inputs with timespecisvalid(3)

2022-05-14 Thread Todd C . Miller
On Sat, 14 May 2022 09:31:26 -0500, Scott Cheloha wrote:

> ok?

OK millert@

 - todd



Re: eliminate use of fseek(3) inside libc

2022-05-13 Thread Todd C . Miller
On Fri, 13 May 2022 19:33:58 -0700, Philip Guenther wrote:

> Diff below converts the last three such uses** and then updates the symbol 
> naming for fseek to block attempts to reference it in the future so uses 
> don't accidentally crawl back in.

OK millert@

 - todd



Re: Mark pw_error __dead in util.h

2022-05-11 Thread Todd C . Miller
On Tue, May 03, 2022 at 10:37:36PM -0500, Matthew Martin wrote:
> The function is already marked __dead in passwd.c, so appears to just be
> an oversight.

Committed, thanks.

 - todd



Re: kstat(1): implement wait with setitimer(2)

2022-05-02 Thread Todd C . Miller
On Mon, 02 May 2022 20:39:07 -0500, Scott Cheloha wrote:

> Whenever I block signals, deraadt@ rises up out of the floorboards and
> says "I hate masking signals, don't do that."
>
> ... but if millert@ is still fine with the attached patch, which does
> sigprocmask(2), I'll go ahead with it.
>
> > Please check the error code of signal(3).
>
> Sure.
>
> > otherwise diff looks good to me
>
> Still look good?

Still OK millert@

 - todd



Re: Merge swap-backed and object-backed inactive lists

2022-05-02 Thread Todd C . Miller
On Mon, 02 May 2022 18:39:17 +0200, Martin Pieuchot wrote:

> Let's simplify the existing logic and use a single list for inactive
> pages.  uvmpd_scan_inactive() already does a lot of check if it finds
> a page which is swap-backed.  This will be improved in a next change.

That looks fine to me.  Calling uvmpd_scan_inactive() a single time
(instead of up to three times!) seems like a win.

 - todd



Re: no gawking in makesyscalls

2022-05-01 Thread Todd C . Miller
On Sun, 01 May 2022 00:48:17 -0400, "Ted Unangst" wrote:

> I don't think we need to concern ourselves with cross awk compatibility here.
>
> Despite the misleading comment, /usr/bin/awk supports toupper.

This must have been to support very old versions of awk (pre-nawk)
since toupper and tolower were added to AT awk in October of 1987.
It is also required by POSIX.

OK millert@

 - todd

>
> Index: makesyscalls.sh
> ===
> RCS file: /home/cvs/src/sys/kern/makesyscalls.sh,v
> retrieving revision 1.15
> diff -u -p -r1.15 makesyscalls.sh
> --- makesyscalls.sh 9 Dec 2021 00:26:10 -   1.15
> +++ makesyscalls.sh 1 May 2022 04:45:49 -
> @@ -70,28 +70,6 @@ sysent="sysent.switch"
>  
>  trap "rm $sysdcl $sysprotos $sysent" 0
>  
> -# Awk program (must support nawk extensions)
> -# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
> -awk=${AWK:-awk}
> -
> -# Does this awk have a "toupper" function? (i.e. is it GNU awk)
> -isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
> -
> -# If this awk does not define "toupper" then define our own.
> -if [ "$isgawk" = TRUE ] ; then
> -   # GNU awk provides it.
> -   toupper=
> -else
> -   # Provide our own toupper()
> -   toupper='
> -function toupper(str) {
> -   _toupper_cmd = "echo "str" |tr a-z A-Z"
> -   _toupper_cmd | getline _toupper_str;
> -   close(_toupper_cmd);
> -   return _toupper_str;
> -}'
> -fi
> -
>  # before handing it off to awk, make a few adjustments:
>  #  (1) insert spaces around {, }, (, ), *, and commas.
>  #  (2) get rid of any and all dollar signs (so that rcs id use safe)
> @@ -111,8 +89,7 @@ s/\$//g
>  2,${
> /^#/!s/\([{}()*,]\)/ \1 /g
>  }
> -' < $2 | $awk "
> -$toupper
> +' < $2 | awk "
>  BEGIN {
> # to allow nested #if/#else/#endif sets
> savedepth = 0



Re: kstat(1): implement wait with setitimer(2)

2022-04-29 Thread Todd C . Miller
On Thu, 28 Apr 2022 20:54:02 -0500, Scott Cheloha wrote:

> Once again, using nanosleep(2) here to print the stats periodically is
> flawed.  The period will drift.  Using setitimer(2)/sigsuspend(2) is
> better.

Yes, I agree that an interval timer is a better fit.

> While here:
>
> - We don't need the hundred million second upper bound anymore.  Just
>   cap the wait at UINT_MAX seconds.
>
> - Use the idiomatic strtonum(3) error message format, it works here.

OK millert@

 - todd



Re: obscure vi crash, fix

2022-04-22 Thread Todd C . Miller
On Fri, 22 Apr 2022 17:38:56 +0200, Theo Buehler wrote:

> I would use an extra variable. The simplification alone is a good
> argument to do it:

Yes, that is nicer.  OK millert@

 - todd



vi: apply expandtab to the output of a ! command

2022-04-22 Thread Todd C . Miller
[I originally sent this a year ago but didn't follow up.]

This is consistent with vim's expandtab behavior.

>From nvi2 (Craig Leres):
https://github.com/lichray/nvi2/commit/7d3f43559026e0927032a105b217850feaefec66

I know most of us don't use expandtab but it is helpful when dealing
with a codebase that is space-indented.  Since the option originated
with vim our behavior should be as compatible as possible.

 - todd

Index: usr.bin/vi/docs/USD.doc/vi.man/vi.1
===
RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.man/vi.1,v
retrieving revision 1.80
diff -u -p -u -r1.80 vi.1
--- usr.bin/vi/docs/USD.doc/vi.man/vi.1 31 Mar 2022 17:27:28 -  1.80
+++ usr.bin/vi/docs/USD.doc/vi.man/vi.1 31 Mar 2022 18:06:35 -
@@ -2356,8 +2356,12 @@ characters to
 when inserting, replacing or shifting text, autoindenting,
 indenting with
 .Aq Ic control-T ,
-or outdenting with
-.Aq Ic control-D .
+outdenting with
+.Aq Ic control-D ,
+or
+when filtering lines with the
+.Cm !\&
+command.
 .It Cm exrc , ex Bq off
 Read the startup files in the local directory.
 .It Cm extended Bq off
Index: usr.bin/vi/ex/ex_bang.c
===
RCS file: /cvs/src/usr.bin/vi/ex/ex_bang.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 ex_bang.c
--- usr.bin/vi/ex/ex_bang.c 18 Apr 2017 01:45:35 -  1.11
+++ usr.bin/vi/ex/ex_bang.c 13 Apr 2021 15:40:47 -
@@ -171,6 +171,10 @@ ex_bang(SCR *sp, EXCMD *cmdp)
if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))
(void)ex_puts(sp, "!\n");
 
+   /* Apply expandtab to the new text */
+   if (O_ISSET(sp, O_EXPANDTAB))
+   ex_retab(sp, cmdp);
+
/*
 * XXX
 * The ! commands never return an error, so that autoprint always
Index: usr.bin/vi/ex/ex_shift.c
===
RCS file: /cvs/src/usr.bin/vi/ex/ex_shift.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 ex_shift.c
--- usr.bin/vi/ex/ex_shift.c30 Apr 2020 10:40:21 -  1.9
+++ usr.bin/vi/ex/ex_shift.c13 Apr 2021 15:40:47 -
@@ -21,7 +21,7 @@
 
 #include "../common/common.h"
 
-enum which {LEFT, RIGHT};
+enum which {RETAB, LEFT, RIGHT};
 static int shift(SCR *, EXCMD *, enum which);
 
 /*
@@ -48,6 +48,18 @@ ex_shiftr(SCR *sp, EXCMD *cmdp)
 }
 
 /*
+ * ex_retab -- Expand tabs (if enabled)
+ *
+ *
+ * PUBLIC: int ex_retab(SCR *, EXCMD *);
+ */
+int
+ex_retab(SCR *sp, EXCMD *cmdp)
+{
+   return (shift(sp, cmdp, RETAB));
+}
+
+/*
  * shift --
  * Ex shift support.
  */
@@ -109,7 +121,9 @@ shift(SCR *sp, EXCMD *cmdp, enum which r
break;
 
/* Calculate the new indent amount. */
-   if (rl == RIGHT)
+   if (rl == RETAB)
+   newcol = oldcol;
+   else if (rl == RIGHT)
newcol = oldcol + sw;
else {
newcol = oldcol < sw ? 0 : oldcol - sw;
Index: usr.bin/vi/include/ex_extern.h
===
RCS file: /cvs/src/usr.bin/vi/include/ex_extern.h,v
retrieving revision 1.16
diff -u -p -u -r1.16 ex_extern.h
--- usr.bin/vi/include/ex_extern.h  27 May 2016 09:18:12 -  1.16
+++ usr.bin/vi/include/ex_extern.h  13 Apr 2021 15:43:01 -
@@ -76,6 +76,7 @@ int ex_set(SCR *, EXCMD *);
 int ex_shell(SCR *, EXCMD *);
 int ex_exec_proc(SCR *, EXCMD *, char *, const char *, int);
 int proc_wait(SCR *, pid_t, const char *, int, int);
+int ex_retab(SCR *, EXCMD *);
 int ex_shiftl(SCR *, EXCMD *);
 int ex_shiftr(SCR *, EXCMD *);
 int ex_source(SCR *, EXCMD *);



Re: obscure vi crash, fix

2022-04-22 Thread Todd C . Miller
Another thing I noticed while testing the fix is that in cl_term_init()
while processing the command mapping there is a missing NULL check.
However, the check _is_ present for the input mapping loop.  The
following diff makes the two loops consistent.

I'm not sure whether this is worth doing since I don't think we can
end up with a NULL command mapping unless c_tklist[] is modified
directly.

 - todd

Index: usr.bin/vi/cl/cl_term.c
===
RCS file: /cvs/src/usr.bin/vi/cl/cl_term.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 cl_term.c
--- usr.bin/vi/cl/cl_term.c 20 Jul 2017 08:37:48 -  1.28
+++ usr.bin/vi/cl/cl_term.c 22 Apr 2022 15:22:57 -
@@ -84,10 +84,17 @@ cl_term_init(SCR *sp)
for (tkp = c_tklist; tkp->name != NULL; ++tkp) {
if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
continue;
-   if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
-   tkp->output, strlen(tkp->output), SEQ_COMMAND,
-   SEQ_NOOVERWRITE | SEQ_SCREEN))
-   return (1);
+   if (tkp->output == NULL) {
+   if (seq_set(sp, tkp->name, strlen(tkp->name),
+   t, strlen(t), NULL, 0,
+   SEQ_COMMAND, SEQ_NOOVERWRITE | SEQ_SCREEN))
+   return (1);
+   } else {
+   if (seq_set(sp, tkp->name, strlen(tkp->name),
+   t, strlen(t), tkp->output, strlen(tkp->output),
+   SEQ_COMMAND, SEQ_NOOVERWRITE | SEQ_SCREEN))
+   return (1);
+   }
}
 
/* Input mappings that are already set or are text deletions. */



Re: obscure vi crash, fix

2022-04-21 Thread Todd C . Miller
On Thu, 21 Apr 2022 09:35:44 -0700, Jeremy Mates wrote:

> The cause is an unguarded use of the NULL output pointer. I am pretty
> sure an .exrc cannot cause this condition (map rhs requires
> something, not nothing) only recompiling with a NULL output string
> for some command.
>
> One fix is to guard the "init_nomap = !e_memcmp(qp->output," line in
> common/key.c with something like
>
>   if (qp->output)
> init_nomap = !e_memcmp(qp->output, >i_event[gp->i_next], qp->ilen);

That seems reasonable to me since the other users of qp->output do
check for NULL.  We don't need to worry about init_nomap being unset
due to the "goto retry" that happens a few lines down.

 - todd

Index: usr.bin/vi/common/key.c
===
RCS file: /cvs/src/usr.bin/vi/common/key.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 key.c
--- usr.bin/vi/common/key.c 18 Apr 2017 01:45:35 -  1.19
+++ usr.bin/vi/common/key.c 21 Apr 2022 17:03:26 -
@@ -650,7 +650,10 @@ not_digit: argp->e_c = CH_NOT_DIGIT;
}
 
/* Find out if the initial segments are identical. */
-   init_nomap = !e_memcmp(qp->output, >i_event[gp->i_next], qp->ilen);
+   if (qp->output != NULL) {
+   init_nomap =
+   !e_memcmp(qp->output, >i_event[gp->i_next], qp->ilen);
+   }
 
/* Delete the mapped characters from the queue. */
QREM(qp->ilen);



Re: login_fbtab glob

2022-04-20 Thread Todd C . Miller
On Wed, 20 Apr 2022 09:18:20 -0500, joshua stein wrote:

> I like it.  Here's the full diff:

OK millert@

 - todd



Re: const openpty et al.

2022-04-20 Thread Todd C . Miller
On Tue, 19 Apr 2022 21:30:25 -0500, Matthew Martin wrote:

> On Thu, Apr 07, 2022 at 06:11:45PM -0500, Matthew Martin wrote:
> > const the termp and winp arguments for openpty and related. This matches
> > the prototypes for openpty and forkpty in glibc and musl libc.
>
> ping; has an ok from tb@ [1]

Committed, thanks.

 - todd



Re: xmss_hash.c: remove superfluous includes

2022-04-19 Thread Todd C . Miller
On Tue, 19 Apr 2022 11:43:35 +0200, Martin Vahlensieck wrote:

> Neither openssl/evp.h nor openssl/hmac.h are required.

Right.

 - todd



Re: ssh-xmss.c: Add missing includes

2022-04-19 Thread Todd C . Miller
On Tue, 19 Apr 2022 11:42:52 +0200, Martin Vahlensieck wrote:

> malloc(3) and friends require stdlib.h, SIZE_MAX requires stdint.h.

You are correct.  The other xmss files get these includes via
xmss_commons.h, but ssh-xmss.c does not.

 - todd



Re: readconf.c: Avoid a xstrdup

2022-04-19 Thread Todd C . Miller
On Tue, 19 Apr 2022 11:41:10 +0200, Martin Vahlensieck wrote:

> There is no need to duplicate options->send_env[i] only free it
> in all cases.  Just use options->send_env[i] directly.

Good catch, match_pattern() takes const char * arguments so
there is no danger there.

 - todd



Re: login_fbtab glob

2022-04-15 Thread Todd C . Miller
On Fri, 15 Apr 2022 13:28:33 -0500, joshua stein wrote:

> Anyone want to bikeshed this language?

I think it is more helpful to refer to glob(7) than glob(3).
Perhaps something like this.

 - todd

Index: share/man/man5/fbtab.5
===
RCS file: /cvs/src/share/man/man5/fbtab.5,v
retrieving revision 1.14
diff -u -p -u -r1.14 fbtab.5
--- share/man/man5/fbtab.5  8 Sep 2014 01:27:55 -   1.14
+++ share/man/man5/fbtab.5  16 Apr 2022 00:52:58 -
@@ -51,15 +51,11 @@ An octal permission number (0600), as us
 .It Other devices
 The final field is a colon
 .Pq Ql \&:
-delimited list of devices (e.g.,
-.Dq /dev/console:/dev/fd0a ) .
-All device names are absolute paths.
-A path that ends in
-.Dq /\&*
-refers to all directory entries except
-.Dq \&.
-and
-.Dq \&.\&. .
+delimited list of device paths (e.g.,
+.Dq /dev/console:/dev/fd0a:/dev/wskbd* ) .
+Device paths may include shell-style globbing patterns (see
+.Xr glob 7 ) ,
+potentially matching multiple devices.
 .El
 .Pp
 The
@@ -83,6 +79,7 @@ the files once again belonging to root.
 .Sh SEE ALSO
 .Xr login 1 ,
 .Xr login_fbtab 3 ,
+.Xr glob 7 ,
 .Xr init 8
 .Sh AUTHORS
 .An Guido van Rooij



Re: login_fbtab glob

2022-04-15 Thread Todd C . Miller
On Fri, 15 Apr 2022 13:12:03 -0500, joshua stein wrote:

> Thanks, both applied.

Looks good to me but needs a man page update.

 - todd



Re: login_fbtab glob

2022-04-15 Thread Todd C . Miller
On Thu, 14 Apr 2022 17:52:37 -0500, joshua stein wrote:

> login_fbtab(3) supports wildcards but only for every file in a 
> directory (/path/*).
>
> This makes it use glob(3) so it can also support more specific 
> wildcards like /path/file*

Yes, it is better to use glob(3) than something custom.
Comments inline.

 - todd

> diff --git lib/libutil/login_fbtab.c lib/libutil/login_fbtab.c
> index 5eacf4f65ff..39621a0cde4 100644
> --- lib/libutil/login_fbtab.c
> +++ lib/libutil/login_fbtab.c
> @@ -61,8 +61,8 @@
>  #include 
>  
>  #include 
> -#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -134,49 +134,32 @@ login_fbtab(const char *tty, uid_t uid, gid_t gid)
>  static void
>  login_protect(const char *path, mode_t mask, uid_t uid, gid_t gid)
>  {
> - charbuf[PATH_MAX];
> - size_t  pathlen = strlen(path);
> - DIR *dir;
> - struct  dirent *ent;
> + glob_t  g;
> + size_t  n;
> + char*gpath;
>  
> - if (pathlen >= sizeof(buf)) {
> + if (strlen(path) > PATH_MAX) {

The test should be >= PATH_MAX since PATH_MAX includes space for
the NUL.

>   errno = ENAMETOOLONG;
>   syslog(LOG_ERR, "%s: %s: %m", _PATH_FBTAB, path);
>   return;
>   }
>  
> - if (strcmp("/*", path + pathlen - 2) != 0) {
> - if (chmod(path, mask) && errno != ENOENT)
> - syslog(LOG_ERR, "%s: chmod(%s): %m", _PATH_FBTAB, path)
> ;
> - if (chown(path, uid, gid) && errno != ENOENT)
> - syslog(LOG_ERR, "%s: chown(%s): %m", _PATH_FBTAB, path)
> ;
> - } else {
> - /*
> -  * This is a wildcard directory (/path/to/whatever/ * ).
> -  * Make a copy of path without the trailing '*' (but leave
> -  * the trailing '/' so we can append directory entries.)
> -  */
> - memcpy(buf, path, pathlen - 1);
> - buf[pathlen - 1] = '\0';
> - if ((dir = opendir(buf)) == NULL) {
> - syslog(LOG_ERR, "%s: opendir(%s): %m", _PATH_FBTAB,
> - path);
> - return;
> - }
> + g.gl_offs = 0;
> + if (glob(path, GLOB_DOOFFS, NULL, ) != 0) {

I don't think you need GLOB_DOOFFS and g.gl_offs here since you are
not reserving slots in gl_pathv.  I would just use GLOB_NOSORT
unless you need things to be sorted.

> + if (errno != ENOENT)
> + syslog(LOG_ERR, "%s: glob(%s): %m", _PATH_FBTAB, path);
> + globfree();
> + return;
> + }
>  
> - while ((ent = readdir(dir)) != NULL) {
> - if (strcmp(ent->d_name, ".")  != 0 &&
> - strcmp(ent->d_name, "..") != 0) {
> - buf[pathlen - 1] = '\0';
> - if (strlcat(buf, ent->d_name, sizeof(buf))
> - >= sizeof(buf)) {
> - errno = ENAMETOOLONG;
> - syslog(LOG_ERR, "%s: %s: %m",
> - _PATH_FBTAB, path);
> - } else
> - login_protect(buf, mask, uid, gid);
> - }
> - }
> - closedir(dir);
> + for (n = 0; n < g.gl_matchc; n++) {
> + gpath = g.gl_pathv[n];
> +
> + if (chmod(gpath, mask) && errno != ENOENT)
> + syslog(LOG_ERR, "%s: chmod(%s): %m", _PATH_FBTAB, gpath
> );
> + if (chown(gpath, uid, gid) && errno != ENOENT)
> + syslog(LOG_ERR, "%s: chown(%s): %m", _PATH_FBTAB, gpath
> );
>   }
> +
> + globfree();
>  }



Re: [diff] gzip verbose message

2022-04-10 Thread Todd C . Miller
On Sun, 10 Apr 2022 13:24:15 +0200, Jeremie Courreges-Anglas wrote:

> The diff below keeps the same output by default and outputs the same as
> GNU gzip(1) is -k is given.

OK millert@

 - todd



Re: vfs: do not export vnode_{hold,free}_list outside kern/vfs_subr.c

2022-03-27 Thread Todd C . Miller
On Sun, 27 Mar 2022 15:05:00 +0200, Sebastien Marie wrote:

> The following diff removes vnode_hold_list, vnode_free_list extern references
> , 
> and `struct freelst` definition from sys/vnode.h
>
> `struct freelst` definition (TAILQ_HEAD) is moved where used, inside vfs_subr
> .c.

OK millert@

 - todd



Re: fix very small ntpd leak

2022-03-23 Thread Todd C . Miller
On Wed, 23 Mar 2022 16:59:06 +0100, Otto Moerbeek wrote:

> This is a bug that dlg reported last week. Serendepity or not? :-)
>
> This is my diff that uses an approach I like a litle bit better.

Since client_peer_init() is always called after new_peer() there's
no reason I can see for query to be a pointer.  You diff seems
better to me too.

 - todd



Re: pfioctl goto fail

2022-03-23 Thread Todd C . Miller
On Wed, 23 Mar 2022 15:53:21 +0100, Alexander Bluhm wrote:

> Hi,
> is a big switch and when looking at a break you need more context
> to see where it jumps to.
>
> I would like to use goto fail consistently to leave the big switch.
> break is used for inner switches and loops.

This makes it easier to reason about that giant switch.
OK millert@

 - todd



setclasscontext: support LOGIN_SETRTABLE too

2022-03-22 Thread Todd C . Miller
I think it makes sense to accept LOGIN_SETRTABLE for setclasscontext(3)
as well.  Currently, it will be cleared out of the flags.

 - todd

Index: lib/libc/gen/login_cap.3
===
RCS file: /cvs/src/lib/libc/gen/login_cap.3,v
retrieving revision 1.19
diff -u -p -u -r1.19 login_cap.3
--- lib/libc/gen/login_cap.34 Mar 2022 08:47:53 -   1.19
+++ lib/libc/gen/login_cap.322 Mar 2022 22:24:30 -
@@ -181,6 +181,7 @@ Only the
 .Dv LOGIN_SETPATH ,
 .Dv LOGIN_SETPRIORITY ,
 .Dv LOGIN_SETRESOURCES ,
+.Dv LOGIN_SETRTABLE ,
 and
 .Dv LOGIN_SETUMASK
 bits are used
Index: lib/libc/gen/login_cap.c
===
RCS file: /cvs/src/lib/libc/gen/login_cap.c,v
retrieving revision 1.44
diff -u -p -u -r1.44 login_cap.c
--- lib/libc/gen/login_cap.c20 Mar 2022 23:24:03 -  1.44
+++ lib/libc/gen/login_cap.c22 Mar 2022 22:24:13 -
@@ -573,7 +573,7 @@ setclasscontext(char *class, u_int flags
login_cap_t *lc;
 
flags &= LOGIN_SETRESOURCES | LOGIN_SETPRIORITY | LOGIN_SETUMASK |
-   LOGIN_SETPATH;
+   LOGIN_SETPATH | LOGIN_SETRTABLE;
 
lc = login_getclass(class);
ret = lc ? setusercontext(lc, NULL, 0, flags) : -1;



Re: issue with login.conf(5) rtable and su -l user

2022-03-13 Thread Todd C . Miller
On Sun, 13 Mar 2022 12:02:03 -0500, Matthew Martin wrote:

> Ignoring -L which already honors rtable, su has three cases:
>   -l (asme=0 asthem=1)
>   -m (asme=1 asthem=0)
>(asme=0 asthem=0)
>
> -l should honor rtable; I am not sure about the other two. I think the
> least suprising would be for the neither case to honor rtable and for -m
> to not, but I don't have a strong opinion here. Patch as suggested below.

Yes, I agree, su(1) should honor the rtable for all but -m.

 - todd



Re: add -k / --keep for gzip(1)

2022-03-13 Thread Todd C . Miller
On Sun, 13 Mar 2022 13:26:13 +0100, Jeremie Courreges-Anglas wrote:

> Works fine.  Here's an updated diff with suggestions:
> - "k" was not completely removed from compress's struct compressor opt
>   string, and was not needed in null_method
> - try to keep the *flag variables ordered
> - rework the condition that decides whether we unlink and print
>   a warning message.  I found the existing code not much readable with
>   a chain of flags check, a syscall and another flag check.
>   Also the new line was over 80 chars.
> - adding "k" to usage can be made shorter since "L" is next to "k"

Looks good to me.  OK millert@ for this version of the diff.

 - todd



Re: ssh: xstrdup(): use memcpy(3)

2022-03-11 Thread Todd C . Miller
On Wed, 09 Mar 2022 19:20:08 -0600, Scott Cheloha wrote:

> The strdup(3) implementation in libc uses memcpy(3), not strlcpy(3).
>
> There is no upside to using strlcpy(3) here if we know the length of
> str before we copy it to the destination buffer.

Sure, using memcpy() here is fine since the length includes space
for the NUL terminator.  OK millert@

 - todd



Re: add -k / --keep for gzip(1)

2022-03-05 Thread Todd C . Miller
On Sun, 06 Mar 2022 02:58:30 +0100, Jeremie Courreges-Anglas wrote:

> I'm not sure what you mean here.  Solene's diff added -k to both
> compress(1) and gzip(1) (and their uncompressor counterparts).
> Adding -k to gzip/gunzip only would indeed make the usage() slightly
> more complicated.
>
> So do we want to add -k to compress(1) or not?  (No strong opinion.)
>
> I like the general idea and the diff seems to work as intended.

I don't really care whether or not we add -k to compress(1).  However,
since other versions of compress do not have a -k option it is
probably best to avoiding adding it.

 - todd



Re: add -k / --keep for gzip(1)

2022-03-03 Thread Todd C . Miller
On Thu, 03 Mar 2022 15:11:13 +, Miod Vallat wrote:

> > I think this makes sense if only for better GNU gzip compatibility.
> > OK millert@
>
> But does the `-k' flag needs to be added to compress(1) too?

No, it just makes usage() slightly more complicated.
But that diff was missing an update to usage() anyway.

 - todd



Re: add -k / --keep for gzip(1)

2022-03-03 Thread Todd C . Miller
On Thu, 03 Mar 2022 13:13:16 +0100, Solene Rapenne wrote:

> The following diff adds support for -k flag to keep the input file for
> gzip / compress when compressing, and the input file (the compressed
> one) for gunzip / uncompress
>
> This will improve uses cases like: zcat -f "${file}" > "${file}.gz"

I think this makes sense if only for better GNU gzip compatibility.
OK millert@

 - todd



Re: httpd: simplify .gz handling a bit

2022-03-02 Thread Todd C . Miller
On Wed, 02 Mar 2022 19:26:46 +0100, Theo Buehler wrote:

> I think it's easier to use a single snprintf call. Also drop a few
> unnecessary parentheses.

Seems like an improvement.  OK millert@

 - todd



Re: [patch] LOGIN_SETENV fails when login.conf is missing

2022-02-26 Thread Todd C . Miller
On Sat, 26 Feb 2022 11:16:44 -0600, Matthew Martin wrote:

> Anton spotted a doas regression failure in t-run-keepenv-path after the
> change to doas for LOGIN_SETALL. Since that test runs doas in a chroot
> and the setup does not create a login.conf, login_getclass in
> login_cap.c will return a login_cap_t with a NULL lc_cap (and errno set
> to ENOENT) on L133. setuserenv returns -1 if lc->lc_cap is NULL causing
> the "could not set user environment" failure.
>
> As all the login_getcap* functions as well as gsetrl and setuserpath
> succeed on a missing login.conf, the below path changes setuserenv to
> return 0 as well. This matches what happens if the class has no setenv
> capability right below. The comment is taken from gsetrl.

Looks good to me.  Unless someone objects I will commit this.

 - todd



Re: seq: check for asprintf failure

2022-02-22 Thread Todd C . Miller
On Wed, 23 Feb 2022 00:04:07 +0100, Theo Buehler wrote:

> Hard to hit. Nevertheless it seems better to error out than to
> crash in strcmp()

Sure.  OK millert@

 - todd



Re: Import seq(1) from FreeBSD

2022-02-21 Thread Todd C . Miller
On Sun, 13 Feb 2022 12:07:31 -0800, Greg Steuck wrote:

> I noticed that despite the OKs the code didn't submitted. Should we
> revive this diff now and continue in the tree?
>
> I have vested interest: I don't want to fix up lang/ghc test suite which
> is full of seq(1).

Here's an updated diff that removes the -t option which is not
present in either the GNU or Plan9 versions.  I've added -h and -v
flag support to be more compatible with the GNU version.

Like the GNU version, this seq always uses a newline terminator and
only displays the separator between numbers (not at the end).  This
is different from the NetBSD version.

 - todd

Index: usr.bin/seq/Makefile
===
RCS file: usr.bin/seq/Makefile
diff -N usr.bin/seq/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.bin/seq/Makefile16 Nov 2020 03:52:57 -
@@ -0,0 +1,8 @@
+#  $OpenBSD$
+
+PROG=  seq
+CFLAGS+= -Wall
+LDADD+=-lm
+DPADD+=${LIBM}
+
+.include 
Index: usr.bin/seq/seq.1
===
RCS file: usr.bin/seq/seq.1
diff -N usr.bin/seq/seq.1
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.bin/seq/seq.1   21 Feb 2022 18:05:31 -
@@ -0,0 +1,197 @@
+.\"$OpenBSD$
+.\"
+.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Brian Ginsbach.
+.\"
+.\" 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 SEQ 1
+.Os
+.Sh NAME
+.Nm seq
+.Nd print sequences of numbers
+.Sh SYNOPSIS
+.Nm
+.Op Fl hvw
+.Op Fl f Ar format
+.Op Fl s Ar string
+.Op Ar first Op Ar incr
+.Ar last
+.Sh DESCRIPTION
+The
+.Nm
+utility prints a sequence of numbers, one per line
+.Pq default ,
+from
+.Ar first
+.Pq default 1 ,
+to near
+.Ar last
+as possible, in increments of
+.Ar incr
+.Pq default 1 .
+When
+.Ar first
+is larger than
+.Ar last ,
+the default
+.Ar incr
+is -1.
+.Pp
+All numbers are interpreted as floating point.
+.Pp
+Normally integer values are printed as decimal integers.
+.Pp
+The
+.Nm
+utility accepts the following options:
+.Bl -tag -width Ar
+.It Fl f Ar format , Fl -format Ar format
+Use a
+.Xr printf 3
+style
+.Ar format
+to print each number.
+Only the
+.Cm A ,
+.Cm a ,
+.Cm E ,
+.Cm e ,
+.Cm F ,
+.Cm f ,
+.Cm G ,
+.Cm g ,
+and
+.Cm %
+conversion characters are valid, along with any optional
+flags and an optional numeric minimum field width or precision.
+The
+.Ar format
+can contain character escape sequences in backslash notation as
+defined in
+.St -ansiC .
+The default is
+.Cm %g .
+.It Fl h , Fl -help
+Display the program usage and exit.
+.It Fl s Ar string , Fl -separator Ar string
+Use
+.Ar string
+to separate numbers.
+The
+.Ar string
+can contain character escape sequences in backslash notation as
+defined in
+.St -ansiC .
+The default is
+.Cm \en .
+.It Fl v , Fl -version
+Display the verion number and exit.
+.It Fl w , Fl -fixed-width
+Equalize the widths of all numbers by padding with zeros as necessary.
+This option has no effect with the
+.Fl f
+option.
+If any sequence numbers will be printed in exponential notation,
+the default conversion is changed to
+.Cm %e .
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+Generate a sequence from 1 to 3 (inclusive) with a default increment of 1:
+.Bd -literal -offset indent
+# seq 1 3
+1
+2
+3
+.Ed
+.Pp
+Generate a sequence from 3 to 1 (inclusive) with a default increment of -1:
+.Bd -literal -offset indent
+# seq 3 1
+3
+2
+1
+.Ed
+.Pp
+Generate a sequence from 0 to 0.1 (inclusive) with an increment of 0.05 and 
padding
+with leading zeroes.
+.Bd 

Re: dhcpleased(8) vs. microsoft dhcp server

2022-02-15 Thread Todd C . Miller
On Tue, 15 Feb 2022 20:18:45 +0100, Florian Obser wrote:

> Also fixes a whitespace issue while here.
>
>   if (dho_len < 1)
>   goto wrong_length;
>
> is redundant now, but I want to keep the pattern of checking the length
> right after identifying the option.

Right, makes sense.  OK millert@

 - todd



  1   2   3   4   5   6   7   8   9   10   >