Re: [patch] ftp(1): change mtime for http/https links

2017-09-22 Thread Philip Guenther
On Sat, 23 Sep 2017, Jesper Wallin wrote:
...
> The patch below will use the Last-Modified header in order to set the
> modification time for http or https links.  I also added, what to me
> looked like a missing "\n" on the error message in ftp.c.
...
> --- fetch.c   7 Mar 2017 08:00:23 -   1.163
> +++ fetch.c   22 Sep 2017 19:52:49 -
...
> @@ -1043,8 +1050,22 @@ cleanup_url_get:
>   fclose(fin);
>   else if (s != -1)
>   close(s);
> - if (out >= 0 && out != fileno(stdout))
> + if (out >= 0 && out != fileno(stdout)) {
> +
> + if (mtime != -1) {
> + struct timeval tv[2];
> + tv[0].tv_sec = time(NULL);
> + tv[0].tv_usec = tv[1].tv_usec = 0;
> + tv[1].tv_sec = mtime;
> +
> + if (futimes(out, tv) == -1)

I would avoid the time() call and use UTIME_NOW and futimens() instead:
if (mtime != -1) {
struct timespec ts[2];

ts[0].tv_nsec = UTIME_NOW;
ts[1].tv_sec = mtime;
tv[1].tv_nsec = 0;
if (futimens(out, ts) == -1)


> + fprintf(ttyout,
> + "Can't change modification time on %s to %s\n",
> + savefile, asctime(localtime()));

asctime(localtime(x)) == ctime(x)


Philip Guenther



perl 5.24.3 update (OK?)

2017-09-22 Thread Andrew Fresh
Hoping this will be able to go in before the lock, I've heard good
things about RC1 working without any issue, so hopefully I can find OKs
from the right folks, so please give it a try and let me know as I'd
really like to pick up some of the other items.

I've got a test release building now, so will be testing myself over the
weekend.

Fortunately, the "incompatible changes" are none, as far as is known:
> There are no changes intentionally incompatible with 5.24.2. If any
> exist, they are bugs, and we request that you submit a report.
> See "Reporting Bugs" below.


The perl changes are described in the perldelta:
(I'd list them here, but it's surprisingly long)
https://metacpan.org/pod/release/SHAY/perl-5.24.3/pod/perldelta.pod


The same fixes that were in RC1 are in the final version.  The only
changes are documentation and a bump of Module::CoreList.
https://perl5.git.perl.org/perl.git/shortlog/refs/heads/maint-5.24


A patch you should be able to apply to -current is here:
http://cvs.afresh1.com/~andrew/perl-update/OpenBSD-perl-5.24.3.patch

Or, you can download the pre-patched files:
(which includes some extra perldeltas and tests that I didn't cvs add)
http://cvs.afresh1.com/~andrew/perl-update/OpenBSD-perl-5.24.3.tar.gz

Or, of course, you can build your own version with what is on github:
https://github.com/afresh1/OpenBSD-perl/
 

l8rZ,
-- 
andrew - http://afresh1.com

Speed matters.  
Almost as much as some things, and nowhere near as much as others.
  -- Nick Holland



Re: [patch] ftp(1): change mtime for http/https links

2017-09-22 Thread Raf Czlonka
On Fri, Sep 22, 2017 at 11:01:57PM BST, Jesper Wallin wrote:
> Hi all,
> 
> My morning routine consists of downloading the latest snapshot files and
> running the upgrade.  To avoid wasting bandwidth and time, I check the
> local modification time of INSTALL.amd64, fetch the remote one and check
> if the modification time has changed.

Hi Jesper,

This is unrelated to your diff but what I do instead is to check
the BUILDINFO file - it's tiny and all the information you need,
is already there.

Cheers,

Raf
 
> A few days ago, the mirror I use had issues with the ftpd.  I quickly
> switched the ftp:// to http:// and continued with my routine.  By doing
> so, I noticed that when running ftp(1) on ftp links, it does preserve
> the modification time.  But for http or https links, the modification
> time is ignored.
> 
> I noticed the 'preserve' option is enabled by default, even when using
> the auto-fetch feature.  I find this behaviour a bit inconsistent and
> unintuitive, seeing it won't let the user specify whether or not the
> preserve option should be enabled.  Yet, it behaves differently
> depending on what protocol we use to fetch the file.
> 
> The patch below will use the Last-Modified header in order to set the
> modification time for http or https links.  I also added, what to me
> looked like a missing "\n" on the error message in ftp.c.
> 
> An alternative solution might be to have the preserve option disabled
> by default when auto-fetching files.
> 
> 
> Jesper Wallin
> 
> 
> Index: fetch.c
> ===
> RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
> retrieving revision 1.163
> diff -u -p -r1.163 fetch.c
> --- fetch.c   7 Mar 2017 08:00:23 -   1.163
> +++ fetch.c   22 Sep 2017 19:52:49 -
> @@ -210,6 +210,7 @@ url_get(const char *origline, const char
>   int status;
>   int save_errno;
>   const size_t buflen = 128 * 1024;
> + time_t mtime = -1;
>  
>   direction = "received";
>  
> @@ -860,6 +861,12 @@ noslash:
>   if (restart_point)
>   filesize += restart_point;
>  #endif /* !SMALL */
> +#define LASTMOD "Last-Modified: "
> + } else if (strncasecmp(cp, LASTMOD, sizeof(LASTMOD) - 1) == 0) {
> + struct tm tm;
> + cp += sizeof(LASTMOD) - 1;
> + if (strptime(cp, "%a, %d %b %Y %T %z", ) != NULL)
> + mtime = mktime();
>  #define LOCATION "Location: "
>   } else if (isredirect &&
>   strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) {
> @@ -1043,8 +1050,22 @@ cleanup_url_get:
>   fclose(fin);
>   else if (s != -1)
>   close(s);
> - if (out >= 0 && out != fileno(stdout))
> + if (out >= 0 && out != fileno(stdout)) {
> +
> + if (mtime != -1) {
> + struct timeval tv[2];
> + tv[0].tv_sec = time(NULL);
> + tv[0].tv_usec = tv[1].tv_usec = 0;
> + tv[1].tv_sec = mtime;
> +
> + if (futimes(out, tv) == -1)
> + fprintf(ttyout,
> + "Can't change modification time on %s to %s\n",
> + savefile, asctime(localtime()));
> + }
> +
>   close(out);
> + }
>   free(buf);
>   free(proxyhost);
>   free(proxyurl);
> Index: ftp.c
> ===
> RCS file: /cvs/src/usr.bin/ftp/ftp.c,v
> retrieving revision 1.100
> diff -u -p -r1.100 ftp.c
> --- ftp.c 22 Aug 2016 16:27:00 -  1.100
> +++ ftp.c 22 Sep 2017 19:52:50 -
> @@ -1217,7 +1217,7 @@ break2:
>   ut.modtime = mtime;
>   if (utime(local, ) == -1)
>   fprintf(ttyout,
> - "Can't change modification time on %s to %s",
> + "Can't change modification time on %s to %s\n",
>   local, asctime(localtime()));
>   }
>   }
> 



Re: [patch] ftp(1): change mtime for http/https links

2017-09-22 Thread Stuart Henderson
I like this, but it's rather late in the release cycle to be adding
features to ftp(1), could you send a reminder when we're at 6.2-current?
(Also, if you haven't already done so, check that "make release" and the
installer still work).



On 2017/09/22 22:01, Jesper Wallin wrote:
> Hi all,
> 
> My morning routine consists of downloading the latest snapshot files and
> running the upgrade.  To avoid wasting bandwidth and time, I check the
> local modification time of INSTALL.amd64, fetch the remote one and check
> if the modification time has changed.
> 
> A few days ago, the mirror I use had issues with the ftpd.  I quickly
> switched the ftp:// to http:// and continued with my routine.  By doing
> so, I noticed that when running ftp(1) on ftp links, it does preserve
> the modification time.  But for http or https links, the modification
> time is ignored.
> 
> I noticed the 'preserve' option is enabled by default, even when using
> the auto-fetch feature.  I find this behaviour a bit inconsistent and
> unintuitive, seeing it won't let the user specify whether or not the
> preserve option should be enabled.  Yet, it behaves differently
> depending on what protocol we use to fetch the file.
> 
> The patch below will use the Last-Modified header in order to set the
> modification time for http or https links.  I also added, what to me
> looked like a missing "\n" on the error message in ftp.c.
> 
> An alternative solution might be to have the preserve option disabled
> by default when auto-fetching files.
> 
> 
> Jesper Wallin
> 
> 
> Index: fetch.c
> ===
> RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
> retrieving revision 1.163
> diff -u -p -r1.163 fetch.c
> --- fetch.c   7 Mar 2017 08:00:23 -   1.163
> +++ fetch.c   22 Sep 2017 19:52:49 -
> @@ -210,6 +210,7 @@ url_get(const char *origline, const char
>   int status;
>   int save_errno;
>   const size_t buflen = 128 * 1024;
> + time_t mtime = -1;
>  
>   direction = "received";
>  
> @@ -860,6 +861,12 @@ noslash:
>   if (restart_point)
>   filesize += restart_point;
>  #endif /* !SMALL */
> +#define LASTMOD "Last-Modified: "
> + } else if (strncasecmp(cp, LASTMOD, sizeof(LASTMOD) - 1) == 0) {
> + struct tm tm;
> + cp += sizeof(LASTMOD) - 1;
> + if (strptime(cp, "%a, %d %b %Y %T %z", ) != NULL)
> + mtime = mktime();
>  #define LOCATION "Location: "
>   } else if (isredirect &&
>   strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) {
> @@ -1043,8 +1050,22 @@ cleanup_url_get:
>   fclose(fin);
>   else if (s != -1)
>   close(s);
> - if (out >= 0 && out != fileno(stdout))
> + if (out >= 0 && out != fileno(stdout)) {
> +
> + if (mtime != -1) {
> + struct timeval tv[2];
> + tv[0].tv_sec = time(NULL);
> + tv[0].tv_usec = tv[1].tv_usec = 0;
> + tv[1].tv_sec = mtime;
> +
> + if (futimes(out, tv) == -1)
> + fprintf(ttyout,
> + "Can't change modification time on %s to %s\n",
> + savefile, asctime(localtime()));
> + }
> +
>   close(out);
> + }
>   free(buf);
>   free(proxyhost);
>   free(proxyurl);
> Index: ftp.c
> ===
> RCS file: /cvs/src/usr.bin/ftp/ftp.c,v
> retrieving revision 1.100
> diff -u -p -r1.100 ftp.c
> --- ftp.c 22 Aug 2016 16:27:00 -  1.100
> +++ ftp.c 22 Sep 2017 19:52:50 -
> @@ -1217,7 +1217,7 @@ break2:
>   ut.modtime = mtime;
>   if (utime(local, ) == -1)
>   fprintf(ttyout,
> - "Can't change modification time on %s to %s",
> + "Can't change modification time on %s to %s\n",
>   local, asctime(localtime()));
>   }
>   }
> 



[patch] ftp(1): change mtime for http/https links

2017-09-22 Thread Jesper Wallin
Hi all,

My morning routine consists of downloading the latest snapshot files and
running the upgrade.  To avoid wasting bandwidth and time, I check the
local modification time of INSTALL.amd64, fetch the remote one and check
if the modification time has changed.

A few days ago, the mirror I use had issues with the ftpd.  I quickly
switched the ftp:// to http:// and continued with my routine.  By doing
so, I noticed that when running ftp(1) on ftp links, it does preserve
the modification time.  But for http or https links, the modification
time is ignored.

I noticed the 'preserve' option is enabled by default, even when using
the auto-fetch feature.  I find this behaviour a bit inconsistent and
unintuitive, seeing it won't let the user specify whether or not the
preserve option should be enabled.  Yet, it behaves differently
depending on what protocol we use to fetch the file.

The patch below will use the Last-Modified header in order to set the
modification time for http or https links.  I also added, what to me
looked like a missing "\n" on the error message in ftp.c.

An alternative solution might be to have the preserve option disabled
by default when auto-fetching files.


Jesper Wallin


Index: fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.163
diff -u -p -r1.163 fetch.c
--- fetch.c 7 Mar 2017 08:00:23 -   1.163
+++ fetch.c 22 Sep 2017 19:52:49 -
@@ -210,6 +210,7 @@ url_get(const char *origline, const char
int status;
int save_errno;
const size_t buflen = 128 * 1024;
+   time_t mtime = -1;
 
direction = "received";
 
@@ -860,6 +861,12 @@ noslash:
if (restart_point)
filesize += restart_point;
 #endif /* !SMALL */
+#define LASTMOD "Last-Modified: "
+   } else if (strncasecmp(cp, LASTMOD, sizeof(LASTMOD) - 1) == 0) {
+   struct tm tm;
+   cp += sizeof(LASTMOD) - 1;
+   if (strptime(cp, "%a, %d %b %Y %T %z", ) != NULL)
+   mtime = mktime();
 #define LOCATION "Location: "
} else if (isredirect &&
strncasecmp(cp, LOCATION, sizeof(LOCATION) - 1) == 0) {
@@ -1043,8 +1050,22 @@ cleanup_url_get:
fclose(fin);
else if (s != -1)
close(s);
-   if (out >= 0 && out != fileno(stdout))
+   if (out >= 0 && out != fileno(stdout)) {
+
+   if (mtime != -1) {
+   struct timeval tv[2];
+   tv[0].tv_sec = time(NULL);
+   tv[0].tv_usec = tv[1].tv_usec = 0;
+   tv[1].tv_sec = mtime;
+
+   if (futimes(out, tv) == -1)
+   fprintf(ttyout,
+   "Can't change modification time on %s to %s\n",
+   savefile, asctime(localtime()));
+   }
+
close(out);
+   }
free(buf);
free(proxyhost);
free(proxyurl);
Index: ftp.c
===
RCS file: /cvs/src/usr.bin/ftp/ftp.c,v
retrieving revision 1.100
diff -u -p -r1.100 ftp.c
--- ftp.c   22 Aug 2016 16:27:00 -  1.100
+++ ftp.c   22 Sep 2017 19:52:50 -
@@ -1217,7 +1217,7 @@ break2:
ut.modtime = mtime;
if (utime(local, ) == -1)
fprintf(ttyout,
-   "Can't change modification time on %s to %s",
+   "Can't change modification time on %s to %s\n",
local, asctime(localtime()));
}
}



Ethernet media autoselect for DEC 3000

2017-09-22 Thread Miod Vallat
The on-board Ethernet interface on DEC 3000 systems (except for models
300) has both a 10base5 and a 10baseT connector, which is software
selected.

The following diff, based upon sparc le@ledma attachment, lets the user
force a specific media regardless of the PROM settings, and will also,
when in 'autoselect' mode, alternate between medias when career is lost.

Tested on 3000/600 (both connectors) and 3000/300LX (10baseT only). This
has zero impact on Ethernet TURBOchannel boards, which use a different
attachment.

Index: dev/tc/if_le_ioasic.c
===
RCS file: /OpenBSD/src/sys/dev/tc/if_le_ioasic.c,v
retrieving revision 1.17
diff -u -p -r1.17 if_le_ioasic.c
--- dev/tc/if_le_ioasic.c   22 Dec 2014 02:28:52 -  1.17
+++ dev/tc/if_le_ioasic.c   22 Sep 2017 20:59:34 -
@@ -55,6 +55,10 @@
 #include 
 #include 
 
+#ifdef __alpha__
+#include 
+#endif /* __alpha__ */
+
 struct le_ioasic_softc {
struct  am7990_softc sc_am7990; /* glue to MI code */
struct  lereg1 *sc_r1;  /* LANCE registers */
@@ -77,6 +81,14 @@ void le_ioasic_copytobuf_gap16(struct la
 void le_ioasic_copyfrombuf_gap16(struct lance_softc *, void *, int, int);
 void le_ioasic_zerobuf_gap16(struct lance_softc *, int, int);
 
+#ifdef __alpha__
+#ifdef DEC_3000_500
+intle_ioasic_ifmedia_change(struct lance_softc *);
+void   le_ioasic_ifmedia_status(struct lance_softc *, struct ifmediareq *);
+void   le_ioasic_nocarrier(struct lance_softc *);
+#endif
+#endif /* __alpha__ */
+
 int
 le_ioasic_match(struct device *parent, void *match, void *aux)
 {
@@ -155,6 +167,27 @@ le_ioasic_attach(struct device *parent, 
le->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
le->sc_zerobuf = le_ioasic_zerobuf_gap16;
 
+#ifdef __alpha__
+#ifdef DEC_3000_500
+   /*
+* On non-300 DEC 3000 models, both AUI and UTP are available.
+*/
+   if (cputype == ST_DEC_3000_500) {
+   static const uint64_t media[] = {
+   IFM_ETHER | IFM_10_T,
+   IFM_ETHER | IFM_10_5,
+   IFM_ETHER | IFM_AUTO
+   };
+   le->sc_mediachange = le_ioasic_ifmedia_change;
+   le->sc_mediastatus = le_ioasic_ifmedia_status;
+   le->sc_supmedia = media;
+   le->sc_nsupmedia = nitems(media);
+   le->sc_defaultmedia = IFM_ETHER | IFM_AUTO;
+   le->sc_nocarrier = le_ioasic_nocarrier;
+   }
+#endif
+#endif /* __alpha__ */
+
dec_le_common_attach(>sc_am7990,
(u_char *)((struct ioasic_softc *)parent)->sc_base
+ IOASIC_SLOT_2_START);
@@ -414,3 +447,96 @@ le_ioasic_zerobuf_gap16(struct lance_sof
xfer = min(len, 16);
}
 }
+
+#ifdef __alpha__
+#ifdef DEC_3000_500
+int
+le_ioasic_ifmedia_change(struct lance_softc *lsc)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   struct ifmedia *ifm = >sc_am7990.lsc.sc_ifmedia;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ossr, ssr;
+
+   if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
+   return EINVAL;
+
+   ossr = ssr = bus_space_read_4(ioasic_bst, ioasic_bsh, IOASIC_CSR);
+
+   switch (IFM_SUBTYPE(ifm->ifm_media)) {
+   case IFM_10_5:
+   ssr &= ~IOASIC_CSR_ETHERNET_UTP;
+   break;
+   case IFM_10_T:
+   ssr |= IOASIC_CSR_ETHERNET_UTP;
+   break;
+   case IFM_AUTO:
+   break;
+   default:
+   return EINVAL;
+   }
+
+   if (ossr != ssr)
+   bus_space_write_4(ioasic_bst, ioasic_bsh, IOASIC_CSR, ssr);
+
+   return 0;
+}
+
+void
+le_ioasic_ifmedia_status(struct lance_softc *lsc, struct ifmediareq *req)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ssr;
+
+   ssr = bus_space_read_4(ioasic_bst, ioasic_bsh, IOASIC_CSR);
+
+   if (ssr & IOASIC_CSR_ETHERNET_UTP)
+   req->ifm_active = IFM_ETHER | IFM_10_T;
+   else
+   req->ifm_active = IFM_ETHER | IFM_10_5;
+}
+
+void
+le_ioasic_nocarrier(struct lance_softc *lsc)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ossr, ssr;
+
+  

Re: malloc.c: better double free check

2017-09-22 Thread Daniel Micay
A linear search works well for the current small quarantine (16) but won't work
well if you ever want to have a larger / configurable quarantine size. It would
also be nice to make this fast enough to enable by default.

We (CopperheadOS) use an open addressed hash table for this based on the
existing hash table since we use a larger quarantine with a FIFO queue
alongside the random array and a configuration size. Ideally the code would be
shared with the existing hash table but I didn't want to make it into an
invasive change downstream.

These are the three downstream patches for OpenBSD malloc in our copy of Bionic
(Android libc), so I'd need to port them to the current upstream code to apply
cleanly. They're currently applied after other changes and it's a slightly
older copy of the base code (after multi-pool support, but before the canary
rework since we'll need to adapt that to our needs). Can get the general idea
from the patches even though they're not going to apply cleanly though.

[1] quarantine double-free detection via hash table

diff --git a/libc/bionic/omalloc.c b/libc/bionic/omalloc.c
index 23af59501..4f4e1290c 100644
--- a/libc/bionic/omalloc.c
+++ b/libc/bionic/omalloc.c
@@ -157,6 +157,7 @@ struct dir_info {
struct region_info free_regions[MALLOC_MAXCACHE];
/* delayed free chunk slots */
void *delayed_chunks[MALLOC_DELAYED_CHUNK_MASK + 1];
+   void *delayed_chunks_set[(MALLOC_DELAYED_CHUNK_MASK + 1) * 4];
size_t rbytesused;  /* random bytes used */
char *func; /* current function */
int mutex;
@@ -292,6 +293,22 @@ hash(void *p)
return sum;
 }
 
+static inline size_t
+hash_chunk(void *p)
+{
+   size_t sum;
+   uintptr_t u;
+
+   u = (uintptr_t)p >> MALLOC_MINSHIFT;
+   sum = u;
+   sum = (sum << 7) - sum + (u >> 16);
+#ifdef __LP64__
+   sum = (sum << 7) - sum + (u >> 32);
+   sum = (sum << 7) - sum + (u >> 48);
+#endif
+   return sum;
+}
+
 static inline
 struct dir_info *getpool(void)
 {
@@ -983,6 +1000,56 @@ delete(struct dir_info *d, struct region_info *ri)
}
 }
 
+void delayed_chunks_insert(struct dir_info *d, void *p)
+{
+   size_t index;
+   size_t mask = sizeof(d->delayed_chunks_set) / sizeof(void *) - 1;
+   void *q;
+
+   index = hash_chunk(p) & mask;
+   q = d->delayed_chunks_set[index];
+   while (q != NULL) {
+   if (p == q)
+   wrterror(d, "double free", p);
+   index = (index - 1) & mask;
+   q = d->delayed_chunks_set[index];
+   }
+   d->delayed_chunks_set[index] = p;
+}
+
+void delayed_chunks_delete(struct dir_info *d, void *p)
+{
+   size_t mask = sizeof(d->delayed_chunks_set) / sizeof(void *) - 1;
+   size_t i, j, r;
+   void *q;
+
+   i = hash_chunk(p) & mask;
+   q = d->delayed_chunks_set[i];
+   while (q != p) {
+   if (q == NULL)
+   wrterror(d, "pointer missing from address tracking 
table", p);
+   i = (i - 1) & mask;
+   q = d->delayed_chunks_set[i];
+   }
+
+   for (;;) {
+   d->delayed_chunks_set[i] = NULL;
+   j = i;
+   for (;;) {
+   i = (i - 1) & mask;
+   if (d->delayed_chunks_set[i] == NULL)
+   return;
+   r = hash_chunk(d->delayed_chunks_set[i]) & mask;
+   if ((i <= r && r < j) || (r < j && j < i) ||
+   (j < i && i <= r))
+   continue;
+   d->delayed_chunks_set[j] = d->delayed_chunks_set[i];
+   break;
+   }
+   }
+}
+
+
 /*
  * Allocate a page of chunks
  */
@@ -1474,11 +1541,21 @@ ofree(struct dir_info *argpool, void *p)
if (!mopts.malloc_freenow) {
if (find_chunknum(pool, r, p) == (uint32_t)-1)
goto done;
+
+   if (p == NULL)
+   goto done;
+
+   delayed_chunks_insert(pool, p);
+
i = getrbyte(pool) & MALLOC_DELAYED_CHUNK_MASK;
tmp = p;
p = pool->delayed_chunks[i];
-   if (tmp == p)
-   wrterror(pool, "double free", p);
+
+   if (p == NULL)
+   goto done;
+
+   delayed_chunks_delete(pool, p);
+
if (mopts.malloc_junk)
validate_junk(pool, p);
pool->delayed_chunks[i] = tmp;
@@ -2264,6 +2341,7 @@ malloc_dump(int fd, struct dir_info *pool)
r = find(pool, p);
if (r == NULL)
wrterror(pool, "bogus pointer in 

relayd http read line

2017-09-22 Thread Alexander Bluhm
Hi,

The relayd regression tests for chunked http traffic fail sometimes.
Ktrace reveals that this happens when the \r and \n at the end of
a header line are read in separate chunks.  Then evbuffer_readline()
interpretes the \r as the end of the first line and the \n as an
additional empty line.  So relayd gets out of sync with the http
protocol.

The function evbuffer_readln() has been added with libevent 1.4.13
in 2010.  With the parameter EVBUFFER_EOL_CRLF the parsing works
reliably.

ok?

bluhm

Index: usr.sbin/relayd/relay.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.226
diff -u -p -r1.226 relay.c
--- usr.sbin/relayd/relay.c 28 Aug 2017 17:31:00 -  1.226
+++ usr.sbin/relayd/relay.c 22 Sep 2017 16:50:51 -
@@ -1679,8 +1679,10 @@ relay_close(struct rsession *con, const 
(void)print_host(>se_in.ss, ibuf, sizeof(ibuf));
(void)print_host(>se_out.ss, obuf, sizeof(obuf));
if (EVBUFFER_LENGTH(con->se_log) &&
-   evbuffer_add_printf(con->se_log, "\r\n") != -1)
-   ptr = evbuffer_readline(con->se_log);
+   evbuffer_add_printf(con->se_log, "\r\n") != -1) {
+   ptr = evbuffer_readln(con->se_log, NULL,
+   EVBUFFER_EOL_CRLF);
+   }
log_info("relay %s, "
"session %d (%d active), %s, %s -> %s:%d, "
"%s%s%s", rlay->rl_conf.name, con->se_id, relay_sessions,
Index: usr.sbin/relayd/relay_http.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relay_http.c,v
retrieving revision 1.66
diff -u -p -r1.66 relay_http.c
--- usr.sbin/relayd/relay_http.c28 May 2017 10:39:15 -  1.66
+++ usr.sbin/relayd/relay_http.c22 Sep 2017 16:44:05 -
@@ -169,14 +169,16 @@ relay_read_http(struct bufferevent *bev,
goto done;
}
 
-   while (!cre->done && (line = evbuffer_readline(src)) != NULL) {
-   linelen = strlen(line);
+   while (!cre->done) {
+   line = evbuffer_readln(src, , EVBUFFER_EOL_CRLF);
+   if (line == NULL)
+   break;
 
/*
 * An empty line indicates the end of the request.
 * libevent already stripped the \r\n for us.
 */
-   if (!linelen) {
+   if (linelen == 0) {
cre->done = 1;
free(line);
break;
@@ -594,7 +596,7 @@ relay_read_httpchunks(struct bufferevent
struct evbuffer *src = EVBUFFER_INPUT(bev);
char*line;
long longllval;
-   size_t   size;
+   size_t   size, linelen;
 
getmonotime(>se_tv_last);
cre->timedout = 0;
@@ -625,13 +627,13 @@ relay_read_httpchunks(struct bufferevent
}
switch (cre->toread) {
case TOREAD_HTTP_CHUNK_LENGTH:
-   line = evbuffer_readline(src);
+   line = evbuffer_readln(src, , EVBUFFER_EOL_CRLF);
if (line == NULL) {
/* Ignore empty line, continue */
bufferevent_enable(bev, EV_READ);
return;
}
-   if (strlen(line) == 0) {
+   if (linelen == 0) {
free(line);
goto next;
}
@@ -660,7 +662,7 @@ relay_read_httpchunks(struct bufferevent
break;
case TOREAD_HTTP_CHUNK_TRAILER:
/* Last chunk is 0 bytes followed by trailer and empty line */
-   line = evbuffer_readline(src);
+   line = evbuffer_readln(src, , EVBUFFER_EOL_CRLF);
if (line == NULL) {
/* Ignore empty line, continue */
bufferevent_enable(bev, EV_READ);
@@ -671,7 +673,7 @@ relay_read_httpchunks(struct bufferevent
free(line);
goto fail;
}
-   if (strlen(line) == 0) {
+   if (linelen == 0) {
/* Switch to HTTP header mode */
cre->toread = TOREAD_HTTP_HEADER;
bev->readcb = relay_read_http;
@@ -680,7 +682,7 @@ relay_read_httpchunks(struct bufferevent
break;
case 0:
/* Chunk is terminated by an empty newline */
-   line = evbuffer_readline(src);
+   line = evbuffer_readln(src, , EVBUFFER_EOL_CRLF);
free(line);
if (relay_bufferevent_print(cre->dst, "\r\n") == -1)
goto fail;



Dell XPS 13 Skylake - wsconsctl blocked from reading backlight state

2017-09-22 Thread Gellert Farkas
Hello,

I am experiencing a problem with my Dell XPS 13 (Skylake) and OpenBSD.
I am running a snapshot that causes a black screen and hang when
trying a start X.

The snapshot is OpenBSD 6.2-beta (dated Mon Sep 18 23:31:27 MDT 2017)

I have found the same bug (albeit from a different type of Skylake
based machine) reported by Bryan Vyhmeister and diagnosed by Mark
Kettenis.

The report and diagnosis of that previous bug is here -
https://marc.info/?l=openbsd-tech=150092763805342

In the reply to Bryan, Mark suggests bringing it to the attention to
the acpi hackers of tech@.

I am seeing the same behavior and see the same process hanging, so I
thought I would send this here as suggested by Mark.

gellert  14799  0.0  0.0   384   328 C0  D+12:56PM0:00.08
wsconsctl 1000 97872   0  10   0 acpilk

I hope this helps, I would be happy to perform any further tests or
provide more verbose information.

Kind Regards

G.



Re: have netstart handle tap interfaces as well as tun

2017-09-22 Thread Stuart Henderson
On 2017/09/22 06:26, Claudio Jeker wrote:
> On Tue, Sep 19, 2017 at 04:54:04PM +1000, David Gwynne wrote:
> > this helsp if you want to have a tap interface joined to a bridge
> > on boot.
> > 
> > ok?
> 
> Uhm, why? bridge is already delayed and tap will be initialized therefore
> before bridge? Neither tun nor tap should be in that list in my opinion
> since they do not depend on other interfaces to be present to initalise
> them.

Hmm - that is used by some openvpn setups.. I don't know if it's still
relevant but the openvpn pkg-readme says

: OpenVPN normally re-creates the tun/tap interface at startup.
: This has been reported to cause problems with some PF configurations
: (especially with queueing), if you run into problems with this then
: OpenVPN should be started from the hostname.* file, e.g.:
: 
: # cat << EOF > /etc/hostname.tun0
: up
: !/usr/local/sbin/openvpn --daemon \
: --config /etc/openvpn/server.conf
: EOF
: 
: (Or use hostname.tap0 for a layer-2 connection).



Re: man page update for bgpctl

2017-09-22 Thread Tom Smyth
Thank you Jason, Denis,
I will learn how to generate proper patches, thanks for your patience and help
Appreciated, will submit more and better ones in future

Thanks
Tom Smyth

On 21 September 2017 at 13:07, Tom Smyth  wrote:
> Hello
> minor Grammar Correction on manual page for bgpctl
>
> - line144
> Take the BGP session to the specified neighbor up.
> +line144
> Bring the BGP session to the specified neighbor up.



malloc.c: better double free check

2017-09-22 Thread Otto Moerbeek
Hi,

Malloc maintains a list if 16 slots of chunks to be freed. On free a
chunk is put in a random slot and the existing chunk in that slot is
actually freed. Currently, the code only checks the slot selected for
a double free.

This diff adds code to check all slots. It also removes the option to
disable delayed free. 

For now, this extra check is only enabled with F. F is also added to S.
As a bonus, the chunk canary corruption check wil also hint at a
double free if applicable.

Please review and test. malloc.conf diff will come later.

-Otto

Index: malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.231
diff -u -p -r1.231 malloc.c
--- malloc.c12 Sep 2017 18:36:30 -  1.231
+++ malloc.c19 Sep 2017 13:04:47 -
@@ -179,7 +179,7 @@ struct chunk_info {
 struct malloc_readonly {
struct dir_info *malloc_pool[_MALLOC_MUTEXES];  /* Main bookkeeping 
information */
int malloc_mt;  /* multi-threaded mode? */
-   int malloc_freenow; /* Free quickly - disable chunk rnd */
+   int malloc_freecheck;   /* Extensive double free check */
int malloc_freeunmap;   /* mprotect free pages PROT_NONE? */
int malloc_junk;/* junk fill? */
int malloc_realloc; /* always realloc? */
@@ -520,11 +520,11 @@ omalloc_parseopt(char opt)
break;
 #endif /* MALLOC_STATS */
case 'f':
-   mopts.malloc_freenow = 0;
+   mopts.malloc_freecheck = 0;
mopts.malloc_freeunmap = 0;
break;
case 'F':
-   mopts.malloc_freenow = 1;
+   mopts.malloc_freecheck = 1;
mopts.malloc_freeunmap = 1;
break;
case 'g':
@@ -605,7 +605,7 @@ omalloc_init(void)
for (; p != NULL && *p != '\0'; p++) {
switch (*p) {
case 'S':
-   for (q = "CGJ"; *q != '\0'; q++)
+   for (q = "CFGJ"; *q != '\0'; q++)
omalloc_parseopt(*q);
mopts.malloc_cache = 0;
break;
@@ -1046,10 +1046,12 @@ validate_canary(struct dir_info *d, u_ch
q = p + check_sz;
 
while (p < q) {
-   if (*p++ != SOME_JUNK) {
-   wrterror(d, "chunk canary corrupted %p %#tx@%#zx",
-   ptr, p - ptr - 1, sz);
+   if (*p != SOME_JUNK) {
+   wrterror(d, "chunk canary corrupted %p %#tx@%#zx%s",
+   ptr, p - ptr, sz, *p == SOME_FREEJUNK ?
+   " (double free?)" : "");
}
+   p++;
}
 }
 
@@ -1381,13 +1383,18 @@ ofree(struct dir_info *argpool, void *p,
unmap(pool, p, PAGEROUND(sz), clear);
delete(pool, r);
} else {
-   void *tmp;
-   int i;
-
-   /* Delayed free or canaries? Extra check */
-   if (!mopts.malloc_freenow || mopts.chunk_canaries)
-   find_chunknum(pool, r, p, mopts.chunk_canaries);
-   if (!clear && !mopts.malloc_freenow) {
+   /* Validate and optionally canary check */
+   find_chunknum(pool, r, p, mopts.chunk_canaries);
+   if (!clear) {
+   void *tmp;
+   int i;
+
+   if (mopts.malloc_freecheck) {
+   for (i = 0; i <= MALLOC_DELAYED_CHUNK_MASK; i++)
+   if (p == pool->delayed_chunks[i])
+   wrterror(pool,
+   "double free %p", p);
+   }
if (mopts.malloc_junk && sz > 0)
memset(p, SOME_FREEJUNK, sz);
i = getrbyte(pool) & MALLOC_DELAYED_CHUNK_MASK;
@@ -1395,13 +1402,11 @@ ofree(struct dir_info *argpool, void *p,
p = pool->delayed_chunks[i];
if (tmp == p)
wrterror(pool, "double free %p", tmp);
+   pool->delayed_chunks[i] = tmp;
if (mopts.malloc_junk)
validate_junk(pool, p);
-   pool->delayed_chunks[i] = tmp;
-   } else {
-   if ((clear || mopts.malloc_junk) && sz > 0)
-   memset(p, clear ? 0 : SOME_FREEJUNK, sz);
-   }
+   } else if (sz > 0)
+   memset(p, 0, sz);
if (p != NULL) {
r = find(pool, p);
if (r == NULL)
@@ -2348,7 

Re: have netstart handle tap interfaces as well as tun

2017-09-22 Thread Claudio Jeker
On Tue, Sep 19, 2017 at 04:54:04PM +1000, David Gwynne wrote:
> this helsp if you want to have a tap interface joined to a bridge
> on boot.
> 
> ok?

Uhm, why? bridge is already delayed and tap will be initialized therefore
before bridge? Neither tun nor tap should be in that list in my opinion
since they do not depend on other interfaces to be present to initalise
them.
 
> Index: netstart
> ===
> RCS file: /cvs/src/etc/netstart,v
> retrieving revision 1.186
> diff -u -p -r1.186 netstart
> --- netstart  25 Jul 2017 21:17:11 -  1.186
> +++ netstart  19 Sep 2017 06:53:10 -
> @@ -255,7 +255,7 @@ fi
>  
>  # Configure all the non-loopback interfaces which we know about, but
>  # do not start interfaces which must be delayed. Refer to hostname.if(5)
> -ifmstart "" "trunk svlan vlan carp gif gre pfsync pppoe tun bridge switch 
> pflow"
> +ifmstart "" "trunk svlan vlan carp gif gre pfsync pppoe tun tap bridge 
> switch pflow"
>  
>  # The trunk interfaces need to come up first in this list.
>  # The (s)vlan interfaces need to come up after trunk.
> @@ -275,7 +275,7 @@ fi
>  # require routes to be set. TUN might depend on PPPoE, and GIF or GRE may
>  # depend on either of them. PFLOW might bind to ip addresses configured
>  # on either of them.
> -ifmstart "pppoe tun gif gre bridge switch pflow"
> +ifmstart "pppoe tun tap gif gre bridge switch pflow"
>  
>  # Reject 127/8 other than 127.0.0.1.
>  route -qn add -net 127 127.0.0.1 -reject >/dev/null
> 

-- 
:wq Claudio