Re: sudo alloc.c -- cleanup required?

2014-04-23 Thread Nayden Markatchev
Hi,

On Wed, Apr 23, 2014 at 8:08 PM, Peter Malone  wrote:

> Hi,
>
> I see something with sudo which I would like to raise with the team. This
> impacts most of the source files in the sudo package.
>
> Before I go down this rat hole, I wanted to run it by you folks to see if
> you agree.
>
> /*
>  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
>  * could be signed (as it is on SunOS 4.x).  This just means that
>  * emalloc2() and erealloc3() cannot allocate huge amounts on such a
>  * platform but that is OK since sudo doesn't need to do so anyway.
>  */
> #ifndef SIZE_MAX
> # ifdef SIZE_T_MAX
> #  define SIZE_MAX  SIZE_T_MAX
> # else
> #  define SIZE_MAX  INT_MAX
> # endif /* SIZE_T_MAX */
> #endif /* SIZE_MAX */
>
> SunOS 4.x? The latest version is 11.x I believe. Can we do without this?
>

​OpenBSD can but this will break it for older SunOS releases. This decision
is up to millert@ but my guess is that if it still here the support is not
going away.

Todd will correct me if I am wrong but the decision for sudo to have
wrappers around malloc was probably chosen for security considerations. On
many OS it is legal have the argument size = 0 and the return in that case
would be a small chunk (12, 16 bytes). emalloc explicitly disallows that
and hence prevents a class of integer related vulnerabilities.
​

>  */
> void *
> emalloc(size)
> size_t size;
> {
>  void *ptr;
>
> if (size == 0)
> errorx(1, "internal error, tried to emalloc(0)");
>
> if ((ptr = malloc(size)) == NULL)
> errorx(1, "unable to allocate memory");
> return(ptr);
> }
>
> /*
>  * emalloc2() allocates nmemb * size bytes and exits with an error
>  * if overflow would occur or if the system malloc(3) fails.
>  */
> void *
> emalloc2(nmemb, size)
> size_t nmemb;
> size_t size;
> {
> void *ptr;
>
> if (nmemb == 0 || size == 0)
> errorx(1, "internal error, tried to emalloc2(0)");
> if (nmemb > SIZE_MAX / size)
> errorx(1, "internal error, emalloc2() overflow");
>
> size *= nmemb;
> if ((ptr = malloc(size)) == NULL)
> errorx(1, "unable to allocate memory");
> return(ptr);
> }
>
>
​There is a bound check in this function that a naive use of malloc(nmemb *
size) will fail to account for and be vulnerable to an overflow.
​

> I'm failing to see the need for these two functions. This could be
> implemented with less code.
>
> In fact, most of alloc.c contains wrapper functions. Some are useful, like
> estrdup(), but could be implemented better (it calls the malloc wrapper).
>
>
​I haven't gone through the rest of the functions in this file but if you
think that the implementations could be improved, give it a shot.

Cheers,
Nayden
​

> Any thoughts on this?
>
>
>
> --
> Peter Malone 
>
>


patch: libssl/src/ssl/t1_enc.c

2014-04-23 Thread Michael W. Bombardieri
Hi tech@, 

Submitting patch to simplify code around free(3) in libssl.
free() already handles the NULL case. 

Does this look ok?

- Michael


Index: t1_enc.c
===
RCS file: /cvs/src/lib/libssl/src/ssl/t1_enc.c,v
retrieving revision 1.26
diff -u -r1.26 t1_enc.c
--- t1_enc.c21 Apr 2014 16:34:43 -  1.26
+++ t1_enc.c24 Apr 2014 05:29:52 -
@@ -1141,10 +1141,8 @@
SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
rv = 0;
 ret:
-   if (buff != NULL)
-   free(buff);
-   if (val != NULL)
-   free(val);
+   free(buff);
+   free(val);
return (rv);
 }
 



[PATCH] xenocara/app/cwm: remove unnecessary zero size check from xmalloc()

2014-04-23 Thread Kent R. Spillner
The diff below removes the check for siz == 0 in xmalloc() because it is
unnecessary.

I was curious about the check for siz == 0 in xmalloc() when I first saw
it, so I dug in further and came to the conclusion it's unnecessary:

* It errors out immediately, so aside from the "zero size" specific error
  message (which users won't see anyways if they start cwm from .xinitrc
  or .xsession) it's not offering any benefit
* malloc() accepts size zero and returns a pointer to memory that will
  SEGFAULT when accessed anyways, so removing this check isn't going to
  hide any errors
* All but one of the existing calls to xmalloc() uses sizeof anyways, so
  there's actually very little chance of siz == 0 in practice
* In fact, there's currently zero chance siz == 0 because the other call
  (in kbfunc_ssh(), kbfunc.c:335) actually passes the value len + 1, so
  even if len was zero -- which it isn't: the value of len comes from
  the fgetln() call on line 330, and fgetln guarantees len > 0 on
  success -- the argument to xmalloc() will always be >= 1 (Unless a
  user has line in ~/.ssh/known_hosts that is SIZE_MAX bytes long, but
  then the memcpy() on the very next line will SEGFAULT anyways)


Index: xmalloc.c
===
RCS file: /work/cvsroot/xenocara/app/cwm/xmalloc.c,v
retrieving revision 1.12
diff -p -u -r1.12 xmalloc.c
--- xmalloc.c   17 Dec 2013 16:12:18 -  1.12
+++ xmalloc.c   24 Apr 2014 03:24:01 -
@@ -37,8 +37,6 @@ xmalloc(size_t siz)
 {
void*p;
 
-   if (siz == 0)
-   errx(1, "xmalloc: zero size");
if ((p = malloc(siz)) == NULL)
err(1, "malloc");
 



Re: [patch src/usr.bin/mg/undo.c] replace malloc & memset with calloc

2014-04-23 Thread Miod Vallat
> Same as the others, this time with src/usr.bin/mg/undo.c

You are now losing a memset() in the `rec doesn't come from malloc' code
path.

> Index: undo.c
> ===
> RCS file: /cvs/src/usr.bin/mg/undo.c,v
> retrieving revision 1.55
> diff -u -p -u -r1.55 undo.c
> --- undo.c20 Mar 2014 07:47:29 -  1.55
> +++ undo.c24 Apr 2014 02:16:16 -
> @@ -89,10 +89,9 @@ new_undo_record(void)
>   TAILQ_REMOVE(&undo_free, rec, next);
>   undo_free_num--;
>   } else {
> - if ((rec = malloc(sizeof(*rec))) == NULL)
> + if ((rec = calloc(1, sizeof(*rec))) == NULL)
>   panic("Out of memory in undo code (record)");
>   }
> - memset(rec, 0, sizeof(struct undo_rec));
>  
>   return (rec);
>  }
> 
> 
> -- 
> Peter Malone 
> 



[PATCH] xenocara/app/cwm: kill unnecessary memset in conf.c

2014-04-23 Thread Kent R. Spillner
The diff below removes an unncessary memset() on line 253 of conf.c.

cwm used to support reloading the config file, but okan@ removed that
functionality about a year ago in favor of simply restarting the whole
thing.  So while it used to be possible to call conf_init() multiple
times, it is now only ever called once when cwm first starts.  The
memset in conf_init() (conf.c:253) was necessary for re-zero'ing out
the configuration each time it was reloaded.  However, now conf_init()
is only ever called once (in main(), calmwm.c:110), and since Conf
is a static variable (calmwm.c:47) the compiler has already initialized
it zero'ed out for us.


Index: conf.c
===
RCS file: /work/cvsroot/xenocara/app/cwm/conf.c,v
retrieving revision 1.173
diff -p -u -r1.173 conf.c
--- conf.c  21 Apr 2014 12:52:14 -  1.173
+++ conf.c  24 Apr 2014 02:53:40 -
@@ -250,8 +250,6 @@ conf_init(struct conf *c)
 {
unsigned inti;
 
-   (void)memset(c, 0, sizeof(*c));
-
c->bwidth = CONF_BWIDTH;
c->mamount = CONF_MAMOUNT;
c->snapdist = CONF_SNAPDIST;



[patch usr.sbin/rwhod/rwhod.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Same as the others, replace malloc & memset with calloc. This time in 
usr.sbin/rwhod/rwhod.c.

Good night!

Index: rwhod.c
===
RCS file: /cvs/src/usr.sbin/rwhod/rwhod.c,v
retrieving revision 1.36
diff -u -p -u -r1.36 rwhod.c
--- rwhod.c 9 Jan 2014 05:04:03 -   1.36
+++ rwhod.c 24 Apr 2014 02:33:08 -
@@ -530,10 +530,9 @@ configure(void)
if (np != NULL)
continue;
len = sizeof(*np) + dstaddr->sa_len + sdl->sdl_nlen + 1;
-   np = (struct neighbor *)malloc(len);
+   np = calloc(1, len);
if (np == NULL)
-   quit("malloc of neighbor structure");
-   memset(np, 0, len);
+   quit("calloc of neighbor structure");
np->n_flags = flags;
np->n_addr = (struct sockaddr *)(np + 1);
np->n_addrlen = dstaddr->sa_len;


-- 
Peter Malone 



[patch usr.sbin/snmpd/mib.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Same as the others. Replace malloc & memset with calloc in usr.sbin/snmpd/mib.c

Index: mib.c
===
RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
retrieving revision 1.67
diff -u -p -u -r1.67 mib.c
--- mib.c   8 Apr 2014 14:04:11 -   1.67
+++ mib.c   24 Apr 2014 02:29:26 -
@@ -2818,9 +2818,8 @@ mib_carpifget(u_int idx)
return (NULL);
}
 
-   cif = malloc(sizeof(struct carpif));
+   cif = calloc(1, sizeof(struct carpif));
if (cif != NULL) {
-   memset(cif, 0, sizeof(struct carpif));
memcpy(&cif->carpr, &carpr, sizeof(struct carpreq));
memcpy(&cif->kif, kif, sizeof(struct kif));
}


-- 
Peter Malone 



[patch src/usr.bin/mg/undo.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Same as the others, this time with src/usr.bin/mg/undo.c

Index: undo.c
===
RCS file: /cvs/src/usr.bin/mg/undo.c,v
retrieving revision 1.55
diff -u -p -u -r1.55 undo.c
--- undo.c  20 Mar 2014 07:47:29 -  1.55
+++ undo.c  24 Apr 2014 02:16:16 -
@@ -89,10 +89,9 @@ new_undo_record(void)
TAILQ_REMOVE(&undo_free, rec, next);
undo_free_num--;
} else {
-   if ((rec = malloc(sizeof(*rec))) == NULL)
+   if ((rec = calloc(1, sizeof(*rec))) == NULL)
panic("Out of memory in undo code (record)");
}
-   memset(rec, 0, sizeof(struct undo_rec));
 
return (rec);
 }


-- 
Peter Malone 



sudo alloc.c -- cleanup required?

2014-04-23 Thread Peter Malone
Hi,

I see something with sudo which I would like to raise with the team. This 
impacts most of the source files in the sudo package.

Before I go down this rat hole, I wanted to run it by you folks to see if you 
agree.

/*
 * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
 * could be signed (as it is on SunOS 4.x).  This just means that
 * emalloc2() and erealloc3() cannot allocate huge amounts on such a
 * platform but that is OK since sudo doesn't need to do so anyway.
 */
#ifndef SIZE_MAX
# ifdef SIZE_T_MAX
#  define SIZE_MAX  SIZE_T_MAX
# else
#  define SIZE_MAX  INT_MAX
# endif /* SIZE_T_MAX */
#endif /* SIZE_MAX */

SunOS 4.x? The latest version is 11.x I believe. Can we do without this? 

Lets look at emalloc() and emalloc2()
/*
 * emalloc() calls the system malloc(3) and exits with an error if
 * malloc(3) fails.
 */
void *
emalloc(size)
size_t size;
{
 void *ptr;

if (size == 0)
errorx(1, "internal error, tried to emalloc(0)");

if ((ptr = malloc(size)) == NULL)
errorx(1, "unable to allocate memory");
return(ptr);
}

/*
 * emalloc2() allocates nmemb * size bytes and exits with an error
 * if overflow would occur or if the system malloc(3) fails.
 */
void *
emalloc2(nmemb, size)
size_t nmemb;
size_t size;
{
void *ptr;

if (nmemb == 0 || size == 0)
errorx(1, "internal error, tried to emalloc2(0)");
if (nmemb > SIZE_MAX / size)
errorx(1, "internal error, emalloc2() overflow");

size *= nmemb;
if ((ptr = malloc(size)) == NULL)
errorx(1, "unable to allocate memory");
return(ptr);
}

I'm failing to see the need for these two functions. This could be implemented 
with less code.

In fact, most of alloc.c contains wrapper functions. Some are useful, like 
estrdup(), but could be implemented better (it calls the malloc wrapper).

Any thoughts on this?



-- 
Peter Malone 



Re: [patch sbin/nfsd/nfsd.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone

Sounds good. I'll work on that tomorrow afternoon/evening.


On 04/23/14 21:55, Ted Unangst wrote:

On Wed, Apr 23, 2014 at 21:38, Peter Malone wrote:

Hi,

Similar to the others. malloc & memset replacement with calloc, this time
in sbin/nfsd/nfsd.c
fd_size = howmany(maxsock + 1, NFDBITS) * sizeof(fd_mask);
-   sockbits = malloc(fd_size);
+   sockbits = calloc(1, fd_size);
ready = malloc(fd_size);

As with ping6, I think this is better converted to poll.




Re: [patch sbin/nfsd/nfsd.c] replace malloc & memset with calloc

2014-04-23 Thread Ted Unangst
On Wed, Apr 23, 2014 at 21:38, Peter Malone wrote:
> Hi,
> 
> Similar to the others. malloc & memset replacement with calloc, this time
> in sbin/nfsd/nfsd.c

>   fd_size = howmany(maxsock + 1, NFDBITS) * sizeof(fd_mask);
> - sockbits = malloc(fd_size);
> + sockbits = calloc(1, fd_size);
>   ready = malloc(fd_size);

As with ping6, I think this is better converted to poll.



Re: [patch bin/systrace/intercept.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
As Ned Flanders infamously said... Take out the crayolas and color me tickled 
pink.

Here's the _actual_ patch.

Index: intercept.c
===
RCS file: /cvs/src/bin/systrace/intercept.c,v
retrieving revision 1.60
diff -u -p -u -r1.60 intercept.c
--- intercept.c 4 Dec 2012 02:24:47 -   1.60
+++ intercept.c 24 Apr 2014 01:42:57 -
@@ -426,10 +426,9 @@ intercept_getpid(pid_t pid)
if (tmp)
return (tmp);
 
-   if ((tmp = malloc(sizeof(struct intercept_pid))) == NULL)
-   err(1, "%s: malloc", __func__);
+   if ((tmp = calloc(1, sizeof(struct intercept_pid))) == NULL)
+   err(1, "%s: calloc", __func__);
 
-   memset(tmp, 0, sizeof(struct intercept_pid));
tmp->pid = pid;
 
SPLAY_INSERT(pidtree, &pids, tmp);



On Wed, 23 Apr 2014 21:35:59 -0400
Ted Unangst  wrote:

> On Wed, Apr 23, 2014 at 21:24, Peter Malone wrote:
> > Hi,
> > 
> > Similar to previous patches replacing malloc & memset with calloc, this
> > time in src/bin/systrace/intercept.c
> > 
> 
> 
> > -   tlnew = malloc(sizeof(struct intercept_translate));
> > +   tlnew = calloc(1, sizeof(struct intercept_translate));
> > if (tlnew == NULL)
> > -   err(1, "%s: %s-%s: malloc",
> > +   err(1, "%s: %s-%s: calloc",
> > __func__, emulation, name);
> >  
> > -   memcpy(tlnew, tl, sizeof(struct intercept_translate));
> 
> Ha, tricked you. :) That's a memcpy.
> 


-- 
Peter Malone 



[patch sbin/nfsd/nfsd.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Similar to the others. malloc & memset replacement with calloc, this time in 
sbin/nfsd/nfsd.c

Index: nfsd.c
===
RCS file: /cvs/src/sbin/nfsd/nfsd.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 nfsd.c
--- nfsd.c  11 Mar 2013 17:40:10 -  1.32
+++ nfsd.c  24 Apr 2014 01:32:04 -
@@ -277,13 +277,12 @@ main(int argc, char *argv[])
 * Allocate space for the fd_set pointers and fill in sockbits
 */
fd_size = howmany(maxsock + 1, NFDBITS) * sizeof(fd_mask);
-   sockbits = malloc(fd_size);
+   sockbits = calloc(1, fd_size);
ready = malloc(fd_size);
if (sockbits == NULL || ready == NULL) {
syslog(LOG_ERR, "cannot allocate memory");
return (1);
}
-   memset(sockbits, 0, fd_size);
if (tcpflag)
FD_SET(tcpsock, sockbits);
 




-- 
Peter Malone 



Re: [patch bin/cp/utils.c] replace malloc & memset with calloc

2014-04-23 Thread Ted Unangst
On Wed, Apr 23, 2014 at 21:15, Peter Malone wrote:

> Similar to previous patches replacing malloc & memset with calloc. This
> time in src/bin/cp/utils.c

Damn, I wrote this code. Thanks.

> Please let me know if this doesn't paste correctly this time. I suspect
> it's ok now. If not, I may just cry.

Yup, applied perfectly.

> I also attached it (I hope that's not frowned upon).

No need now that inline is working.



Re: [patch bin/systrace/intercept.c] replace malloc & memset with calloc

2014-04-23 Thread Ted Unangst
On Wed, Apr 23, 2014 at 21:24, Peter Malone wrote:
> Hi,
> 
> Similar to previous patches replacing malloc & memset with calloc, this
> time in src/bin/systrace/intercept.c
> 


> - tlnew = malloc(sizeof(struct intercept_translate));
> + tlnew = calloc(1, sizeof(struct intercept_translate));
>   if (tlnew == NULL)
> - err(1, "%s: %s-%s: malloc",
> + err(1, "%s: %s-%s: calloc",
>   __func__, emulation, name);
>  
> - memcpy(tlnew, tl, sizeof(struct intercept_translate));

Ha, tricked you. :) That's a memcpy.



[patch bin/systrace/intercept.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Similar to previous patches replacing malloc & memset with calloc, this time in 
src/bin/systrace/intercept.c

Index: intercept.c
===
RCS file: /cvs/src/bin/systrace/intercept.c,v
retrieving revision 1.60
diff -u -p -u -r1.60 intercept.c
--- intercept.c 4 Dec 2012 02:24:47 -   1.60
+++ intercept.c 24 Apr 2014 01:20:47 -
@@ -155,12 +155,11 @@ intercept_register_translation(char *emu
errx(1, "%s: %s-%s: can't find call back",
__func__, emulation, name);
 
-   tlnew = malloc(sizeof(struct intercept_translate));
+   tlnew = calloc(1, sizeof(struct intercept_translate));
if (tlnew == NULL)
-   err(1, "%s: %s-%s: malloc",
+   err(1, "%s: %s-%s: calloc",
__func__, emulation, name);
 
-   memcpy(tlnew, tl, sizeof(struct intercept_translate));
tlnew->off = offset;
 
TAILQ_INSERT_TAIL(&tmp->tls, tlnew, next);






-- 
Peter Malone 


intercept.c
Description: Binary data


[patch bin/cp/utils.c] replace malloc & memset with calloc

2014-04-23 Thread Peter Malone
Hi,

Similar to previous patches replacing malloc & memset with calloc. This time in 
src/bin/cp/utils.c

Please let me know if this doesn't paste correctly this time. I suspect it's ok 
now. If not, I may just cry.

I also attached it (I hope that's not frowned upon).

Cheers!



Index: utils.c
===
RCS file: /cvs/src/bin/cp/utils.c,v
retrieving revision 1.33
diff -u -p -u -r1.33 utils.c
--- utils.c 11 Jul 2012 16:19:24 -  1.33
+++ utils.c 24 Apr 2014 00:51:42 -
@@ -63,10 +63,9 @@ copy_file(FTSENT *entp, int dne)
err(1, "malloc");
}
if (!zeroes) {
-   zeroes = malloc(MAXBSIZE);
+   zeroes = calloc(1, MAXBSIZE);
if (!zeroes)
-   err(1, "malloc");
-   memset(zeroes, 0, MAXBSIZE);
+   err(1, "calloc");
}
 
if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {






-- 
Peter Malone 


utils.patch
Description: Binary data


Re: libssl/src/crypto/x86_64cpuid.pl Vallhalla breakage

2014-04-23 Thread Ted Unangst
On Thu, Apr 24, 2014 at 00:21, Ian Mcwilliam wrote:
> (cd /usr/src/lib/libcrypto/crypto/../../libssl/src/crypto/ ;
> /usr/bin/perl ./x86_64cpuid.pl) > x86_64cpuid.S
> syntax error at ./x86_64cpuid.pl line 198, near "print"
> Execution of ./x86_64cpuid.pl aborted due to compilation errors.
> *** Error 255 in lib/libcrypto/crypto (arch/amd64/Makefile.inc:54
> 'x86_64cpuid.S')
> *** Error 1 in lib/libcrypto (:48 'realdepend')
> *** Error 1 in lib (:48 'depend')
> *** Error 1 in /usr/src (Makefile:78 'build')

fixed thanks.



libssl/src/crypto/x86_64cpuid.pl Vallhalla breakage

2014-04-23 Thread Ian Mcwilliam
(cd /usr/src/lib/libcrypto/crypto/../../libssl/src/crypto/ ;  /usr/bin/perl 
./x86_64cpuid.pl) > x86_64cpuid.S
syntax error at ./x86_64cpuid.pl line 198, near "print"
Execution of ./x86_64cpuid.pl aborted due to compilation errors.
*** Error 255 in lib/libcrypto/crypto (arch/amd64/Makefile.inc:54 
'x86_64cpuid.S')
*** Error 1 in lib/libcrypto (:48 'realdepend')
*** Error 1 in lib (:48 'depend')
*** Error 1 in /usr/src (Makefile:78 'build')


Ian McWilliam



Index: x86_64cpuid.pl
===
RCS file: /cvs/src/lib/libssl/src/crypto/x86_64cpuid.pl,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 x86_64cpuid.pl
--- x86_64cpuid.pl      23 Apr 2014 21:53:18 -      1.9
+++ x86_64cpuid.pl      24 Apr 2014 00:18:57 -
@@ -161,7 +161,7 @@ OPENSSL_ia32_cpuid:
 .size  OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
 ___
 
-print<<___ 
+print<<___;
 .globl OPENSSL_wipe_cpu
 .type  OPENSSL_wipe_cpu,\@abi-omnipotent
 .align 16



Re: libssl/src/apps don't cast {m,re}alloc

2014-04-23 Thread Jean-Philippe Ouellet
This doesn't fix the problems, only removes markers alerting us to audit it.

Memory management in these files is still missing integer overflow checks,
NULL return checks, and is full of crazy abominations like:

X509_NAME *
parse_name(char *subject, long chtype, int multirdn)
{
size_t buflen = strlen(subject) + 1;/* ...
char *buf = malloc(buflen);
size_t max_ne = buflen / 2 + 1; /* maximum number of name elements */
char **ne_types = malloc(max_ne * sizeof(char *));
char **ne_values = malloc(max_ne * sizeof(char *));
int *mval = malloc(max_ne * sizeof(int));

I'm working on a more complete patch which addresses these issues too.



Re: ahci BSY retry

2014-04-23 Thread Ian Darwin
On 2014-04-23 3:50 PM, Chris Cappuccio wrote:
> Peter J. Philipp recently ran into this on his Intel AHCI+Intel SSD
> system (see misc from yesterday):
>
> ahci2 at pci0 dev 31 function 2 "Intel 8 Series AHCI" rev 0x05: msi, AHCI 1.3
> ahci2: device on port 1 didn't come ready, TFD: 0x80
> ahci2: stopping the port, softreset slot 31 was still active.
> ahci2: unable to communicate with device on port 1
>
> I've seen this on boot with Intel AHCI and Transcend SSD and others
> have seen it with Intel AHCI+Intel SSD on soekris net6501.
>
> Here's a simple fix based on Dragonfly's fix for the same problem.
> (Try to restablish communication one more time.)

Seems to unbreak suspend/resume on my Dell Studio with Intel AHCI (before
your fix it had to be in legacy/ATA mode in the BIOS).



Re: wol support for bge

2014-04-23 Thread Mark Kettenis
> Date: Wed, 23 Apr 2014 11:43:06 -0500
> From: Abel Abraham Camarillo Ojeda 
> 
> This should work on sparc64?

Unlikely.



libssl/src/apps don't cast {m,re}alloc

2014-04-23 Thread Thomas Pfaff
Don't cast {m,re}alloc.  No point and it's inconsistent already.

Index: apps.c
===
RCS file: /cvs/src/lib/libssl/src/apps/apps.c,v
retrieving revision 1.42
diff -u -p -r1.42 apps.c
--- apps.c  22 Apr 2014 14:54:13 -  1.42
+++ apps.c  23 Apr 2014 07:20:29 -
@@ -216,7 +216,7 @@ chopup_args(ARGS * arg, char *buf, int *
i = 0;
if (arg->count == 0) {
arg->count = 20;
-   arg->data = (char **)malloc(sizeof(char *) * arg->count);
+   arg->data = malloc(sizeof(char *) * arg->count);
}
for (i = 0; i < arg->count; i++)
arg->data[i] = NULL;
@@ -236,8 +236,7 @@ chopup_args(ARGS * arg, char *buf, int *
if (num >= arg->count) {
char **tmp_p;
int tlen = arg->count + 20;
-   tmp_p = (char **) realloc(arg->data,
-   sizeof(char *) * tlen);
+   tmp_p = realloc(arg->data, sizeof(char *) * tlen);
if (tmp_p == NULL)
return 0;
arg->data = tmp_p;
@@ -417,7 +416,7 @@ password_callback(char *buf, int bufsiz,
ok = UI_add_input_string(ui, prompt, ui_flags, buf,
PW_MIN_LENGTH, bufsiz - 1);
if (ok >= 0 && verify) {
-   buff = (char *) malloc(bufsiz);
+   buff = malloc(bufsiz);
ok = UI_add_verify_string(ui, prompt, ui_flags, buff,
PW_MIN_LENGTH, bufsiz - 1, buf);
}
Index: ca.c
===
RCS file: /cvs/src/lib/libssl/src/apps/ca.c,v
retrieving revision 1.46
diff -u -p -r1.46 ca.c
--- ca.c22 Apr 2014 13:32:17 -  1.46
+++ ca.c23 Apr 2014 07:20:29 -
@@ -1981,17 +1981,17 @@ again2:
goto err;
 
/* We now just add it to the database */
-   row[DB_type] = (char *) malloc(2);
+   row[DB_type] = malloc(2);
 
tm = X509_get_notAfter(ret);
-   row[DB_exp_date] = (char *) malloc(tm->length + 1);
+   row[DB_exp_date] = malloc(tm->length + 1);
memcpy(row[DB_exp_date], tm->data, tm->length);
row[DB_exp_date][tm->length] = '\0';
 
row[DB_rev_date] = NULL;
 
/* row[DB_serial] done already */
-   row[DB_file] = (char *) malloc(8);
+   row[DB_file] = malloc(8);
row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0);
 
if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
@@ -2003,8 +2003,7 @@ again2:
row[DB_type][0] = 'V';
row[DB_type][1] = '\0';
 
-   if ((irow = (char **)malloc(sizeof(char *) * (DB_NUMBER + 1))) ==
-   NULL) {
+   if ((irow = malloc(sizeof(char *) * (DB_NUMBER + 1))) == NULL) {
BIO_printf(bio_err, "Memory allocation failure\n");
goto err;
}
@@ -2245,17 +2244,17 @@ do_revoke(X509 * x509, CA_DB * db, int t
row[DB_serial], row[DB_name]);
 
/* We now just add it to the database */
-   row[DB_type] = (char *) malloc(2);
+   row[DB_type] = malloc(2);
 
tm = X509_get_notAfter(x509);
-   row[DB_exp_date] = (char *) malloc(tm->length + 1);
+   row[DB_exp_date] = malloc(tm->length + 1);
memcpy(row[DB_exp_date], tm->data, tm->length);
row[DB_exp_date][tm->length] = '\0';
 
row[DB_rev_date] = NULL;
 
/* row[DB_serial] done already */
-   row[DB_file] = (char *) malloc(8);
+   row[DB_file] = malloc(8);
 
/* row[DB_name] done already */
 
@@ -2268,7 +2267,7 @@ do_revoke(X509 * x509, CA_DB * db, int t
row[DB_type][0] = 'V';
row[DB_type][1] = '\0';
 
-   if ((irow = (char **)malloc(sizeof(char *) *
+   if ((irow = malloc(sizeof(char *) *
(DB_NUMBER + 1))) == NULL) {
BIO_printf(bio_err, "Memory allocation failure\n");
goto err;
@@ -2405,7 +2404,7 @@ do_updatedb(CA_DB * db)
 
/* get actual time and make a string */
a_tm = X509_gmtime_adj(a_tm, 0);
-   a_tm_s = (char *) malloc(a_tm->length + 1);
+   a_tm_s = malloc(a_tm->length + 1);
if (a_tm_s == NULL) {
cnt = -1;
goto err;
Index: dgst.c
===
RCS file: /cvs/src/lib/libssl/src/apps/dgst.c,v
retrieving revision 1.27
diff -u -p -r1.27 dgst.c
--- dgst.c  18 Apr 2014 19:54:57 -  1.27
+++ dgst.c  23 Apr 2014 07:20:30 -
@@ -132,7 +132,7 @@ dgst_main(int argc, char **argv)
 
apps_startup();
 
-   if ((buf = (uns

[PATCH] ssh: variables never read

2014-04-23 Thread Fritjof Bornebusch
Hi tech,

there are some unread set operations in the ssh code.

Fritjof

Index: clientloop.c
===
RCS file: /cvs/src/usr.bin/ssh/clientloop.c,v
retrieving revision 1.258
diff -u -p -r1.258 clientloop.c
--- clientloop.c2 Feb 2014 03:44:31 -   1.258
+++ clientloop.c23 Apr 2014 19:50:18 -
@@ -934,7 +934,6 @@ process_cmdline(void)
 
/* XXX update list of forwards in options */
if (delete) {
-   cancel_port = 0;
cancel_host = hpdelim(&s);  /* may be NULL */
if (s != NULL) {
cancel_port = a2port(s);


Index: krl.c
===
RCS file: /cvs/src/usr.bin/ssh/krl.c,v
retrieving revision 1.14
diff -u -p -r1.14 krl.c
--- krl.c   31 Jan 2014 16:39:19 -  1.14
+++ krl.c   23 Apr 2014 19:55:50 -
@@ -496,7 +496,6 @@ choose_next_state(int current_state, u_i
if (cost_bitmap_restart < cost) {
new_state = KRL_SECTION_CERT_SERIAL_BITMAP;
*force_new_section = 1;
-   cost = cost_bitmap_restart;
}
debug3("%s: contig %llu last_gap %llu next_gap %llu final %d, 
costs:"
"list %llu range %llu bitmap %llu new bitmap %llu, "
@@ -957,7 +956,6 @@ ssh_krl_from_blob(Buffer *buf, struct ss
/* Not interested for now. */
continue;
}
-   sig_seen = 1;
/* First string component is the signing key */
if ((key = key_from_blob(blob, blen)) == NULL) {
error("%s: invalid signature key", __func__);


Index: readconf.c
===
RCS file: /cvs/src/usr.bin/ssh/readconf.c,v
retrieving revision 1.219
diff -u -p -r1.219 readconf.c
--- readconf.c  23 Apr 2014 12:42:34 -  1.219
+++ readconf.c  23 Apr 2014 20:01:26 -
@@ -1255,7 +1255,7 @@ parse_int:
if (!arg || *arg == '\0')
fatal("%.200s line %d: Missing ControlPersist"
" argument.", filename, linenum);
-   value = 0;
+
value2 = 0; /* timeout */
if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
value = 0;


Index: scp.c
===
RCS file: /cvs/src/usr.bin/ssh/scp.c,v
retrieving revision 1.179
diff -u -p -r1.179 scp.c
--- scp.c   20 Nov 2013 20:53:10 -  1.179
+++ scp.c   23 Apr 2014 20:05:22 -
@@ -818,7 +818,6 @@ next:   if (fd != -1) {
if (fd != -1) {
if (close(fd) < 0 && !haderr)
haderr = errno;
-   fd = -1;
}
if (!haderr)
(void) atomicio(vwrite, remout, "", 1);


Index: sftp.c
===
RCS file: /cvs/src/usr.bin/ssh/sftp.c,v
retrieving revision 1.160
diff -u -p -r1.160 sftp.c
--- sftp.c  22 Apr 2014 10:07:12 -  1.160
+++ sftp.c  23 Apr 2014 20:11:54 -
@@ -1222,7 +1222,6 @@ parse_args(const char **cpp, int *ignore
*aflag = *fflag = *hflag = *iflag = *lflag = *pflag = 0;
*rflag = *sflag = 0;
*path1 = *path2 = NULL;
-   optidx = 1;
switch (cmdnum) {
case I_GET:
case I_REGET:



ahci BSY retry

2014-04-23 Thread Chris Cappuccio
Peter J. Philipp recently ran into this on his Intel AHCI+Intel SSD
system (see misc from yesterday):

ahci2 at pci0 dev 31 function 2 "Intel 8 Series AHCI" rev 0x05: msi, AHCI 1.3
ahci2: device on port 1 didn't come ready, TFD: 0x80
ahci2: stopping the port, softreset slot 31 was still active.
ahci2: unable to communicate with device on port 1

I've seen this on boot with Intel AHCI and Transcend SSD and others
have seen it with Intel AHCI+Intel SSD on soekris net6501.

Here's a simple fix based on Dragonfly's fix for the same problem.
(Try to restablish communication one more time.)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/f2dba7003b2add226b3999a41a99fd278cc5a26f

Dragonfly will only reset here on startup, whereas OpenBSD will
call this to reset ports after startup. This symptom occurred to
me during >24 hour heavy 100% read+write utilization on softraid
RAID1 configuration, with regular SATA disks. So if we are going 
to call ahci_port_portreset during operation, this seems prudent.

Index: ahci.c
===
RCS file: /cvs/src/sys/dev/ic/ahci.c,v
retrieving revision 1.13
diff -u -r1.13 ahci.c
--- ahci.c  14 Apr 2014 04:42:22 -  1.13
+++ ahci.c  23 Apr 2014 14:11:16 -
@@ -1363,7 +1363,7 @@
 ahci_port_portreset(struct ahci_port *ap, int pmp)
 {
u_int32_t   cmd, r;
-   int rc, s;
+   int rc, s, retries = 0;
 
s = splbio();
DPRINTF(AHCI_D_VERBOSE, "%s: port reset\n", PORTNAME(ap));
@@ -1378,6 +1378,10 @@
ahci_pwrite(ap, AHCI_PREG_SCTL, 0);
delay(1);
r = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_INIT;
+
+   ahci_pwrite(ap, AHCI_PREG_SCTL, r);
+retry:
+   delay(1);
if ((ap->ap_sc->sc_dev.dv_cfdata->cf_flags & 0x01) != 0) {
DPRINTF(AHCI_D_VERBOSE, "%s: forcing GEN1\n", PORTNAME(ap));
r |= AHCI_PREG_SCTL_SPD_GEN1;
@@ -1411,6 +1415,10 @@
/* even if the device doesn't wake up, check if there's
 * a port multiplier there
 */
+   if (retries == 0) {
+   retries = 1;
+   goto retry;
+   }
rc = EBUSY;
} else {
rc = 0;



Re: [patch] cvs some values never read

2014-04-23 Thread Fritjof Bornebusch

 * Fritjof Bornebusch  [2014-04-23 20:15]:
 > 
 >   * Fritjof Bornebusch  [2014-04-23 19:30]:
 >   > there are some set operations, which are never read.
 >   
 >   > RCS file: /cvs/src/usr.bin/cvs/rcsparse.c,v
 >   
 >   guess we need to decide what to do with opencvs really. either 
there
 >   is someone who cares and picks it up, or we can straight 
delete it. it
 >   hasn't moved forward in years, and I have a hard time seeing 
it going
 >   anywhere (except Attic). But that's just me, of course.
 >   
 > If opencvs is going to be deleted, what is the alternative? gnucvs?
 
 err, that's what we've been using all the time. It has never become
 ready.
 
 revision 1.114
 date: 2010/06/26 03:59:34;  author: deraadt;  state: Exp;  lines: +2 
-2;
 disable opencvs; maintainers went bye bye
 
Ah, I see.
 -- 
 Henning Brauer, h...@bsws.de, henn...@openbsd.org
 BS Web Services GmbH, http://bsws.de, Full-Service ISP
 Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to 
Fully Managed
 Henning Brauer Consulting, http://henningbrauer.com/
 



Re: [patch] cvs some values never read

2014-04-23 Thread Henning Brauer
* Fritjof Bornebusch  [2014-04-23 20:15]:
> 
>* Fritjof Bornebusch  [2014-04-23 19:30]:
>> there are some set operations, which are never read.
>
>> RCS file: /cvs/src/usr.bin/cvs/rcsparse.c,v
>
>guess we need to decide what to do with opencvs really. either there
>is someone who cares and picks it up, or we can straight delete it. it
>hasn't moved forward in years, and I have a hard time seeing it going
>anywhere (except Attic). But that's just me, of course.
>
> If opencvs is going to be deleted, what is the alternative? gnucvs?

err, that's what we've been using all the time. It has never become
ready.

revision 1.114
date: 2010/06/26 03:59:34;  author: deraadt;  state: Exp;  lines: +2 -2;
disable opencvs; maintainers went bye bye

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services GmbH, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



Re: [patch] cvs some values never read

2014-04-23 Thread Fritjof Bornebusch

 * Fritjof Bornebusch  [2014-04-23 19:30]:
 > there are some set operations, which are never read.
 
 > RCS file: /cvs/src/usr.bin/cvs/rcsparse.c,v
 
 guess we need to decide what to do with opencvs really. either there
 is someone who cares and picks it up, or we can straight delete it. it
 hasn't moved forward in years, and I have a hard time seeing it going
 anywhere (except Attic). But that's just me, of course.
 
If opencvs is going to be deleted, what is the alternative? gnucvs?
 --
 Henning Brauer, h...@bsws.de, henn...@openbsd.org
 BS Web Services GmbH, http://bsws.de, Full-Service ISP
 Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to 
Fully Managed
 Henning Brauer Consulting, http://henningbrauer.com/
 
Fritjof



Re: [PATCH] usr.bin/sdiff/sdiff.c prompt bikeshedding

2014-04-23 Thread Kent R. Spillner
Moar bikeshedding:


Index: sdiff.c
===
RCS file: /work/cvsroot/src/usr.bin/sdiff/sdiff.c,v
retrieving revision 1.30
diff -p -u -r1.30 sdiff.c
--- sdiff.c 26 Nov 2013 21:08:12 -  1.30
+++ sdiff.c 23 Apr 2014 17:58:07 -
@@ -419,8 +419,8 @@ prompt(const char *s1, const char *s2)
 {
char *cmd;
 
-   /* Print command prompt. */
-   putchar('%');
+#define PROMPT_STR "%% "
+   printf(PROMPT_STR);
 
/* Get user input. */
for (; (cmd = xfgets(stdin)); free(cmd)) {
@@ -473,7 +473,7 @@ prompt(const char *s1, const char *s2)
 USAGE:
int_usage();
 PROMPT:
-   putchar('%');
+   printf(PROMPT_STR);
 
/* Prompt user again. */
continue;



Re: [patch] cvs some values never read

2014-04-23 Thread Henning Brauer
* Fritjof Bornebusch  [2014-04-23 19:30]:
> there are some set operations, which are never read.

> RCS file: /cvs/src/usr.bin/cvs/rcsparse.c,v

guess we need to decide what to do with opencvs really. either there
is someone who cares and picks it up, or we can straight delete it. it
hasn't moved forward in years, and I have a hard time seeing it going
anywhere (except Attic). But that's just me, of course.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services GmbH, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



[PATCH] xenocara/app/cwm: don't require quotes in autogroup configuration

2014-04-23 Thread Kent R. Spillner
I think I sent this out a long time ago but never followed up on it.  :(

According to cwmrc(5) you can configure an autogroup like so:

autogroup group windowname,windowclass

However, parse.y doesn't actually accept that syntax; you have to put
quotes around windowname,windowclass so they're recognized as a single
string value, and then conf_autogroup() splits them apart later.

This diff adds support to parse.y for recognizing the literal syntax
as specified in the man page without the need for quotes (while
retaining support for the quoted values for backwards compatibility).

For example, today you have to put this in your .cwmrc:

autogroup 2 "Navigator,Firefox"

But with this diff you could use the following instead:

autogroup 2 Navigator,Firefox


Index: calmwm.h
===
RCS file: /work/cvsroot/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.259
diff -p -u -r1.259 calmwm.h
--- calmwm.h8 Feb 2014 02:49:30 -   1.259
+++ calmwm.h23 Apr 2014 17:32:02 -
@@ -500,7 +500,8 @@ void menuq_clear(struct menu_q *);
 int parse_config(const char *, struct conf *);
 
 voidconf_atoms(void);
-voidconf_autogroup(struct conf *, int, const char *);
+voidconf_autogroup(struct conf *, int, const char *,
+const char *);
 int conf_bind_kbd(struct conf *, const char *,
 const char *);
 int conf_bind_mouse(struct conf *, const char *,
Index: conf.c
===
RCS file: /work/cvsroot/xenocara/app/cwm/conf.c,v
retrieving revision 1.173
diff -p -u -r1.173 conf.c
--- conf.c  21 Apr 2014 12:52:14 -  1.173
+++ conf.c  23 Apr 2014 17:18:11 -
@@ -78,19 +78,31 @@ conf_cmd_remove(struct conf *c, const ch
}
 }
 void
-conf_autogroup(struct conf *c, int no, const char *val)
+conf_autogroup(struct conf *c, int no, const char *class, const char *name)
 {
struct autogroupwin *aw;
char*p;
+   const char  *tmp;
 
aw = xcalloc(1, sizeof(*aw));
 
-   if ((p = strchr(val, ',')) == NULL) {
-   aw->name = NULL;
-   aw->class = xstrdup(val);
+   if ((p = strchr(class, ',')) == NULL) {
+   if (name == NULL)
+   aw->name = NULL;
+   else
+   aw->name = xstrdup(name);
+
+   aw->class = xstrdup(class);
} else {
+   tmp = class;
+
*(p++) = '\0';
-   aw->name = xstrdup(val);
+
+   if (name == NULL)
+   aw->name = xstrdup(tmp);
+   else
+   aw->name = xstrdup(name);
+
aw->class = xstrdup(p);
}
aw->num = no;
Index: parse.y
===
RCS file: /work/cvsroot/xenocara/app/cwm/parse.y,v
retrieving revision 1.58
diff -p -u -r1.58 parse.y
--- parse.y 30 Jan 2014 22:41:16 -  1.58
+++ parse.y 23 Apr 2014 17:10:49 -
@@ -152,8 +152,18 @@ main   : FONTNAME STRING   {
yyerror("invalid autogroup: %d", $2);
YYERROR;
}
-   conf_autogroup(conf, $2, $3);
+   conf_autogroup(conf, $2, $3, NULL);
free($3);
+   }
+   | AUTOGROUP NUMBER STRING ',' STRING{
+   if ($2 < 0 || $2 > 9) {
+   free($3);
+   yyerror("invalid autogroup: %d", $2);
+   YYERROR;
+   }
+   conf_autogroup(conf, $2, $5, $3);
+   free($3);
+   free($5);
}
| IGNORE STRING {
conf_ignore(conf, $2);



[patch] cvs some values never read

2014-04-23 Thread Fritjof Bornebusch
Hi tech,

there are some set operations, which are never read.

Fritjof

Index: rcsparse.c
===
RCS file: /cvs/src/usr.bin/cvs/rcsparse.c,v
retrieving revision 1.7
diff -u -p -r1.7 rcsparse.c
--- rcsparse.c  3 Jun 2013 17:04:35 -   1.7
+++ rcsparse.c  23 Apr 2014 17:09:44 -
@@ -916,7 +916,6 @@ rcsparse_token(RCSFILE *rfp, int allowed
} while (isspace(c));
 
pdp->rp_msglineno = pdp->rp_lineno;
-   type = 0;
switch (c) {
case '@':
ret = rcsparse_string(rfp, allowed);
@@ -1105,7 +1104,6 @@ rcsparse(RCSFILE *rfp, struct rcs_sectio
int i, token;
 
pdp = (struct rcs_pdata *)rfp->rf_pdata;
-   i = 0;
 
token = 0;
for (i = 0; sec[i].token != 0; i++) {



Index: diff_internals.c
===
RCS file: /cvs/src/usr.bin/cvs/diff_internals.c,v
retrieving revision 1.34
diff -u -p -r1.34 diff_internals.c
--- diff_internals.c1 Apr 2011 17:25:26 -   1.34
+++ diff_internals.c23 Apr 2014 17:10:19 -
@@ -1375,7 +1375,7 @@ dump_unified_vec(FILE *f1, FILE *f2, int
if (context_vec_start > context_vec_ptr)
return;
 
-   b = d = 0;  /* gcc */
+   d = 0;  /* gcc */
lowa = MAX(1, cvp->a - diff_context);
upb = MIN(len[0], context_vec_ptr->b + diff_context);
lowc = MAX(1, cvp->c - diff_context);


Index: getlog.c
===
RCS file: /cvs/src/usr.bin/cvs/getlog.c,v
retrieving revision 1.97
diff -u -p -r1.97 getlog.c
--- getlog.c8 Jan 2014 13:23:55 -   1.97
+++ getlog.c23 Apr 2014 17:11:59 -
@@ -318,7 +318,7 @@ log_rev_print(struct rcs_delta *rdp)
struct rcs_branch *rb;
struct rcs_delta *nrdp;
 
-   i = found = 0;
+   found = 0;
 
/* -s states */
if (runflags & L_STATES) {


Index: rcs.c
===
RCS file: /cvs/src/usr.bin/cvs/rcs.c,v
retrieving revision 1.311
diff -u -p -r1.311 rcs.c
--- rcs.c   8 Jan 2014 13:23:55 -   1.311
+++ rcs.c   23 Apr 2014 17:21:39 -
@@ -293,8 +293,6 @@ rcs_write(RCSFILE *rfp)
size_t len;
int fd, saved_errno;
 
-   fd = -1;
-
if (rfp->rf_flags & RCS_SYNCED)
return;
 
@@ -2229,7 +2227,6 @@ rcs_kwexp_line(char *rcsfile, struct rcs
return;
 
c = line->l_line;
-   found = 0;
/* Final character in buffer. */
fin = c + len - 1;
 
@@ -2503,7 +2500,6 @@ rcs_kwexp_line(char *rcsfile, struct rcs
lp->l_len = strlen(lp->l_line);
TAILQ_INSERT_AFTER(&(lines->l_lines), cur, lp,
l_list);
-   cur = lp;
 
end = line->l_line + line->l_len - 1;



Re: wol support for bge

2014-04-23 Thread Abel Abraham Camarillo Ojeda
I know that, I just think I could do something fun with that box today...

On Wed, Apr 23, 2014 at 11:54 AM, Stefan Sperling  wrote:
> On Wed, Apr 23, 2014 at 11:43:06AM -0500, Abel Abraham Camarillo Ojeda wrote:
>> This should work on sparc64?
>
> I have no idea, honestly.
>
> But I don't see the point since sparc64 can often be powered up
> remotely via ALOM.



Re: wol support for bge

2014-04-23 Thread Stefan Sperling
On Wed, Apr 23, 2014 at 11:43:06AM -0500, Abel Abraham Camarillo Ojeda wrote:
> This should work on sparc64?

I have no idea, honestly.

But I don't see the point since sparc64 can often be powered up
remotely via ALOM.



Re: wol support for bge

2014-04-23 Thread Abel Abraham Camarillo Ojeda
This should work on sparc64?

if so I can test in my sunfire v210... - this box isn't set up to
build a kernel so it will be some work to make it build -

On Wed, Apr 23, 2014 at 11:15 AM, Stefan Sperling  wrote:
> The reason we don't enable WOL with bge cards is that they contain
> ASF firmware support which should not be exposed to untrusted traffic,
> so it's safer to power down bge devices altogether on power down.
> Since all bges except the rare 5700 version support ASF, this currently
> means no WOL support for bge cards at all.
>
> (If you want to know what's so bad about ASF, search the net for
> security problems with intel AMT -- ASF is a precursor to this.)
>
> Apparently there is an eeprom configuration bit that tells us
> if ASF is enabled or not. Can we trust this bit?
> If we decide that the bit is trustworthy enough, we could allow
> users to enable wol for bge cards as long as ASF is disabled
> (yet I'd still want a warning in the man page).
>
> The diff below tries to do this. I don't have any hardware to test
> with so I'd be delighted if some bge owners could give this a spin.
> If this doesn't make wol work and the problem can't be fixed, then
> we can skip the entire ASF discussion anyway.
>
> To test this:
>
>  - recompile your kernel with the below diff
>  - reboot
>  - run 'ifconfig bge0 wol'
>  - run 'shutdown -hp now'
>  - try to send a magic packet from another machine with 'arp -W MAC_ADDR'
>and hope for the bge box to power back up
>
> If it doesn't work, please check your BIOS for WOL and ASF-related
> configuration settings and check if tweaking them helps.
>
> Thanks.
>
> Index: mii/brgphyreg.h
> ===
> RCS file: /cvs/src/sys/dev/mii/brgphyreg.h,v
> retrieving revision 1.16
> diff -u -p -r1.16 brgphyreg.h
> --- mii/brgphyreg.h 13 Jan 2013 05:40:05 -  1.16
> +++ mii/brgphyreg.h 23 Apr 2014 14:11:06 -
> @@ -206,6 +206,7 @@
>  #define BRGPHY_AUXCTL_TX_TST   0x0400  /* TX test, always 1 */
>  #define BRGPHY_AUXCTL_DIS_PRF  0x0080  /* dis part resp filter */
>  #define BRGPHY_AUXCTL_DIAG_MODE0x0004  /* Diagnostic mode */
> +#define BRGPHY_AUXCTL_WOL_ENBL 0x000A  /* Enable WOL */
>
>  #define BRGPHY_MII_AUXSTS  0x19/* AUX status */
>  #define BRGPHY_AUXSTS_ACOMP0x8000  /* autoneg complete */
> Index: pci/if_bge.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_bge.c,v
> retrieving revision 1.353
> diff -u -p -r1.353 if_bge.c
> --- pci/if_bge.c24 Feb 2014 20:00:48 -  1.353
> +++ pci/if_bge.c23 Apr 2014 15:33:54 -
> @@ -202,6 +202,10 @@ void bge_sig_pre_reset(struct bge_softc
>  void bge_stop_fw(struct bge_softc *, int);
>  void bge_reset(struct bge_softc *);
>  void bge_link_upd(struct bge_softc *);
> +#ifndef SMALL_KERNEL
> +int bge_wol(struct ifnet *, int);
> +void bge_wol_power(struct bge_softc *);
> +#endif
>
>  void bge_ape_lock_init(struct bge_softc *);
>  void bge_ape_read_fw_ver(struct bge_softc *);
> @@ -3064,6 +3068,35 @@ bge_attach(struct device *parent, struct
> if (BGE_IS_5755_PLUS(sc) && sc->bge_flags & BGE_MSI)
> CSR_WRITE_4(sc, BGE_MSI_MODE, CSR_READ_4(sc, BGE_MSI_MODE) &
> ~BGE_MSIMODE_ONE_SHOT_DISABLE);
> +
> +#ifndef SMALL_KERNEL
> +   if (hwcfg & BGE_HWCFG_NO_GPIO2)
> +   sc->bge_flags |= BGE_NO_GPIO2;
> +
> +   if (BGE_ASICREV(sc->bge_chipid) != BGE_ASICREV_BCM5700) {
> +   /* Check if ASF is enabled. */
> +   if (!(sc->bge_flags & BGE_NO_EEPROM)) {
> +   if (bge_read_eeprom(sc, (caddr_t)&hwcfg,
> +   BGE_EE_FEATURE_CFG_OFFSET, sizeof(hwcfg)) == 0) {
> +   hwcfg = ntohl(hwcfg);
> +   if (hwcfg & BGE_HWCFG_ASF)
> +   sc->bge_flags |= BGE_ASF_MODE;
> +   }
> +   } else if (hwcfg & BGE_HWCFG_ASF) {
> +   sc->bge_flags |= BGE_ASF_MODE;
> +   }
> +   }
> +
> +   /* Allow WoL if ASF is unsupported or disabled. */
> +   if (!(sc->bge_flags & BGE_ASF_MODE)) {
> +   ifp->if_capabilities |= IFCAP_WOL;
> +   ifp->if_wol = bge_wol;
> +
> +   /* This heuristic matches the Linux driver. */
> +   if (!(hwcfg & BGE_HWCFG_EEPROM_WRITE_PROTECT))
> +   sc->bge_flags |= BGE_WOL_NEEDS_VAUX;
> +   }
> +#endif
>
> /* Hookup IRQ last. */
> DPRINTFN(5, ("pci_intr_establish\n"));
> @@ -3160,6 +3193,9 @@ bge_activate(struct device *self, int ac
> rv = config_activate_children(self, act);
> if (ifp->if_flags & IFF_RUNNING)
> bge_stop(sc);
> +#ifndef SMALL_KERNEL
> +   bge_wol_power(sc);
> +#endif
> break;
> case DVACT_RESUME:
>   

wol support for bge

2014-04-23 Thread Stefan Sperling
The reason we don't enable WOL with bge cards is that they contain
ASF firmware support which should not be exposed to untrusted traffic,
so it's safer to power down bge devices altogether on power down.
Since all bges except the rare 5700 version support ASF, this currently
means no WOL support for bge cards at all.

(If you want to know what's so bad about ASF, search the net for
security problems with intel AMT -- ASF is a precursor to this.)

Apparently there is an eeprom configuration bit that tells us
if ASF is enabled or not. Can we trust this bit?
If we decide that the bit is trustworthy enough, we could allow
users to enable wol for bge cards as long as ASF is disabled
(yet I'd still want a warning in the man page).

The diff below tries to do this. I don't have any hardware to test
with so I'd be delighted if some bge owners could give this a spin.
If this doesn't make wol work and the problem can't be fixed, then
we can skip the entire ASF discussion anyway.  

To test this:

 - recompile your kernel with the below diff
 - reboot
 - run 'ifconfig bge0 wol'
 - run 'shutdown -hp now'
 - try to send a magic packet from another machine with 'arp -W MAC_ADDR'
   and hope for the bge box to power back up

If it doesn't work, please check your BIOS for WOL and ASF-related
configuration settings and check if tweaking them helps.

Thanks.

Index: mii/brgphyreg.h
===
RCS file: /cvs/src/sys/dev/mii/brgphyreg.h,v
retrieving revision 1.16
diff -u -p -r1.16 brgphyreg.h
--- mii/brgphyreg.h 13 Jan 2013 05:40:05 -  1.16
+++ mii/brgphyreg.h 23 Apr 2014 14:11:06 -
@@ -206,6 +206,7 @@
 #define BRGPHY_AUXCTL_TX_TST   0x0400  /* TX test, always 1 */
 #define BRGPHY_AUXCTL_DIS_PRF  0x0080  /* dis part resp filter */
 #define BRGPHY_AUXCTL_DIAG_MODE0x0004  /* Diagnostic mode */
+#define BRGPHY_AUXCTL_WOL_ENBL 0x000A  /* Enable WOL */
 
 #define BRGPHY_MII_AUXSTS  0x19/* AUX status */
 #define BRGPHY_AUXSTS_ACOMP0x8000  /* autoneg complete */
Index: pci/if_bge.c
===
RCS file: /cvs/src/sys/dev/pci/if_bge.c,v
retrieving revision 1.353
diff -u -p -r1.353 if_bge.c
--- pci/if_bge.c24 Feb 2014 20:00:48 -  1.353
+++ pci/if_bge.c23 Apr 2014 15:33:54 -
@@ -202,6 +202,10 @@ void bge_sig_pre_reset(struct bge_softc 
 void bge_stop_fw(struct bge_softc *, int);
 void bge_reset(struct bge_softc *);
 void bge_link_upd(struct bge_softc *);
+#ifndef SMALL_KERNEL
+int bge_wol(struct ifnet *, int);
+void bge_wol_power(struct bge_softc *);
+#endif
 
 void bge_ape_lock_init(struct bge_softc *);
 void bge_ape_read_fw_ver(struct bge_softc *);
@@ -3064,6 +3068,35 @@ bge_attach(struct device *parent, struct
if (BGE_IS_5755_PLUS(sc) && sc->bge_flags & BGE_MSI)
CSR_WRITE_4(sc, BGE_MSI_MODE, CSR_READ_4(sc, BGE_MSI_MODE) &
~BGE_MSIMODE_ONE_SHOT_DISABLE);
+   
+#ifndef SMALL_KERNEL
+   if (hwcfg & BGE_HWCFG_NO_GPIO2)
+   sc->bge_flags |= BGE_NO_GPIO2;
+
+   if (BGE_ASICREV(sc->bge_chipid) != BGE_ASICREV_BCM5700) {
+   /* Check if ASF is enabled. */
+   if (!(sc->bge_flags & BGE_NO_EEPROM)) {
+   if (bge_read_eeprom(sc, (caddr_t)&hwcfg,
+   BGE_EE_FEATURE_CFG_OFFSET, sizeof(hwcfg)) == 0) {
+   hwcfg = ntohl(hwcfg);
+   if (hwcfg & BGE_HWCFG_ASF)
+   sc->bge_flags |= BGE_ASF_MODE;
+   }
+   } else if (hwcfg & BGE_HWCFG_ASF) {
+   sc->bge_flags |= BGE_ASF_MODE;
+   }
+   }
+
+   /* Allow WoL if ASF is unsupported or disabled. */
+   if (!(sc->bge_flags & BGE_ASF_MODE)) {
+   ifp->if_capabilities |= IFCAP_WOL;
+   ifp->if_wol = bge_wol;
+
+   /* This heuristic matches the Linux driver. */
+   if (!(hwcfg & BGE_HWCFG_EEPROM_WRITE_PROTECT))
+   sc->bge_flags |= BGE_WOL_NEEDS_VAUX;
+   }
+#endif
 
/* Hookup IRQ last. */
DPRINTFN(5, ("pci_intr_establish\n"));
@@ -3160,6 +3193,9 @@ bge_activate(struct device *self, int ac
rv = config_activate_children(self, act);
if (ifp->if_flags & IFF_RUNNING)
bge_stop(sc);
+#ifndef SMALL_KERNEL
+   bge_wol_power(sc);
+#endif
break;
case DVACT_RESUME:
if (ifp->if_flags & IFF_UP)
@@ -4728,3 +4764,177 @@ bge_link_upd(struct bge_softc *sc)
BGE_MACSTAT_CFG_CHANGED|BGE_MACSTAT_MI_COMPLETE|
BGE_MACSTAT_LINK_CHANGED);
 }
+
+#ifndef SMALL_KERNEL
+int
+bge_wol(struct ifnet *ifp, int enable)
+{
+   struct bge_softc *sc = ifp->if_softc;
+
+   if (enable)
+   sc->bge_flags |= BGE_WOL;
+   else
+   sc->bge_

Re: AI_ADDRCONFIG

2014-04-23 Thread Simon Perreault
Le 2014-04-23 11:43, Stuart Henderson a écrit :
> On 2014/04/23 08:09, Simon Perreault wrote:
>> +else if (ifa->ifa_addr->sa_family == PF_INET6 &&
> 
> so... family is ipv6
> 
>> +!IN6_IS_ADDR_LOOPBACK(
>> +&((struct sockaddr_in6 *)ifa->ifa_addr)
>> +->sin6_addr) &&
> 
> AND it's not a loopback address
> 
>> +!((ifa->ifa_flags & IFF_LOOPBACK) &&
>> +IN6_IS_ADDR_LINKLOCAL(
>> +&((struct sockaddr_in6 *)ifa->ifa_addr)
>> +->sin6_addr)))
> 
> AND NOT (loopback interface AND link-local address)
> 
> But the intention seems to be "if you have a usable v6 address
> that stands a chance of being routable" - so shouldn't this last bit
> be "AND NOT loopback interface AND NOT link-local address"?
> 
> !(ifa->ifa_flags & IFF_LOOPBACK) && !(IN6_IS_ADDR_LINKLOCAL(
> &((struct sockaddr_in6 *)ifa->ifa_addr)))
> 
> Otherwise AI_ADDRCONFIG will still allow v6 addresses if you have a
> default OpenBSD configuration i.e. the automatically configured
> link-local address on an ethernet interface even if you've done nothing
> to try and make them work.
> 
> I suspect it may not be quite RFC compliant, but I think actual usability
> trumps RFC compliance here.

Yes, you're right, I over-thought things here. Will send an updated diff
later today.

Thanks a lot for your thorough review!

Simon



Re: AI_ADDRCONFIG

2014-04-23 Thread Stuart Henderson
On 2014/04/23 08:09, Simon Perreault wrote:
> + else if (ifa->ifa_addr->sa_family == PF_INET6 &&

so... family is ipv6

> + !IN6_IS_ADDR_LOOPBACK(
> + &((struct sockaddr_in6 *)ifa->ifa_addr)
> + ->sin6_addr) &&

AND it's not a loopback address

> + !((ifa->ifa_flags & IFF_LOOPBACK) &&
> + IN6_IS_ADDR_LINKLOCAL(
> + &((struct sockaddr_in6 *)ifa->ifa_addr)
> + ->sin6_addr)))

AND NOT (loopback interface AND link-local address)

But the intention seems to be "if you have a usable v6 address
that stands a chance of being routable" - so shouldn't this last bit
be "AND NOT loopback interface AND NOT link-local address"?

!(ifa->ifa_flags & IFF_LOOPBACK) && !(IN6_IS_ADDR_LINKLOCAL(
&((struct sockaddr_in6 *)ifa->ifa_addr)))

Otherwise AI_ADDRCONFIG will still allow v6 addresses if you have a
default OpenBSD configuration i.e. the automatically configured
link-local address on an ethernet interface even if you've done nothing
to try and make them work.

I suspect it may not be quite RFC compliant, but I think actual usability
trumps RFC compliance here.



Re: AI_ADDRCONFIG

2014-04-23 Thread Brad Smith
On Wed, Apr 23, 2014 at 08:09:06AM -0400, Simon Perreault wrote:
> (I sent this diff to ??ric Faurot on the 12th, but received no reply.)
> 
> Tech,
> 
> While everyone's having fun removing code from OpenSSL, I decided to add
> some to libasr. I implemented AI_ADDRCONFIG, a getaddrinfo() flag defined in
> RFC 2553/3493. Basically, it tells getaddrinfo() to skip IPvX lookups when
> there are no IPvX addresses configured on any interface. It is present on
> most other OSes. Tons of software out there have to play Autoconf games to
> cope with its absence (which, on OpenBSD, predates libasr if I'm not
> mistaken).
> 
> Noteworthy:
> 
> - I call getifaddrs() from getaddrinfo_run_async(). This should not block,
> so no need to change the state machine.
> 
> - I added AI_ADDRCONFIG to the default hints, like glibc does, and as was
> specified in RFC 2553. (RFC 3493 says nothing about default flags.)
> 
> ok? comments?

Great! I had been asking Eric about this.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



ping/ping6 minor cleanup

2014-04-23 Thread Jérémie Courrèges-Anglas
j...@wxcvbn.org (Jérémie Courrèges-Anglas) writes:

> Florian Obser  writes:
>
>> On Tue, Apr 22, 2014 at 03:08:45PM -0400, pe...@petermalone.org wrote:
>>> Thanks Florian & team.
>>> 
>>> Please review the following diff.
>>
>> tab vs. space, more in sync with ping6
>> OK?
>
> ok.

Some changes I'd like:
- I find fdmaskp badly named, a remnant of when select was used
- recvfrom returns an ssize_t, cc shouldn't be (ab)used for poll's
  return value.
- the scope of cc, fdmaskp/pfd and timeout can be reduced
- add a bit more of whitespace to make things more readable

Index: ping/ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.101
diff -u -p -r1.101 ping.c
--- ping/ping.c 23 Apr 2014 12:27:31 -  1.101
+++ ping/ping.c 23 Apr 2014 13:01:01 -
@@ -178,10 +178,8 @@ main(int argc, char *argv[])
 {
struct hostent *hp;
struct sockaddr_in *to;
-   struct pollfd fdmaskp[1];
struct in_addr saddr;
-   int i, ch, hold = 1, packlen, preload, maxsize, df = 0, tos = 0;
-   int timeout;
+   int ch, hold = 1, i, packlen, preload, maxsize, df = 0, tos = 0;
u_char *datap, *packet, ttl = MAXTTL, loop = 1;
char *target, hnamebuf[MAXHOSTNAMELEN];
 #ifdef IP_OPTIONS
@@ -509,26 +507,31 @@ main(int argc, char *argv[])
 
for (;;) {
struct sockaddr_in from;
-   sigset_t omask, nmask;
-   socklen_t fromlen;
-   int cc;
+   sigset_tomask, nmask;
+   socklen_t   fromlen;
+   struct pollfd   pfd;
+   ssize_t cc;
+   int ret, timeout;
 
if (options & F_FLOOD) {
pinger();
timeout = 10;
} else
timeout = INFTIM;
-   fdmaskp[0].fd = s;
-   fdmaskp[0].events = POLLIN;
-   cc = poll(fdmaskp, 1, timeout);
-   if (cc < 0) {
+
+   pfd.fd = s;
+   pfd.events = POLLIN;
+
+   ret = poll(&pfd, 1, timeout);
+   if (ret < 0) {
if (errno != EINTR) {
warn("poll");
sleep(1);
}
continue;
-   } else if (cc == 0)
+   } else if (ret == 0)
continue;
+
fromlen = sizeof(from);
if ((cc = recvfrom(s, packet, packlen, 0,
(struct sockaddr *)&from, &fromlen)) < 0) {
Index: ping6/ping6.c
===
RCS file: /cvs/src/sbin/ping6/ping6.c,v
retrieving revision 1.88
diff -u -p -r1.88 ping6.c
--- ping6/ping6.c   10 Jan 2014 21:57:44 -  1.88
+++ ping6/ping6.c   23 Apr 2014 13:01:07 -
@@ -250,11 +250,8 @@ main(int argc, char *argv[])
 {
struct itimerval itimer;
struct sockaddr_in6 from;
-   int timeout;
struct addrinfo hints;
-   struct pollfd fdmaskp[1];
-   int cc, i;
-   int ch, hold, packlen, preload, optval, ret_ga;
+   int ch, hold, i, packlen, preload, optval, ret_ga;
u_char *datap, *packet;
char *e, *target, *ifname = NULL, *gateway = NULL;
const char *errstr;
@@ -887,12 +884,15 @@ main(int argc, char *argv[])
 #endif
 
for (;;) {
-   struct msghdr m;
+   struct msghdr   m;
union {
struct cmsghdr hdr;
u_char buf[CMSG_SPACE(1024)];
-   } cmsgbuf;
-   struct iovec iov[2];
+   }   cmsgbuf;
+   struct ioveciov[2];
+   struct pollfd   pfd;
+   ssize_t cc;
+   int ret, timeout;
 
/* signal handling */
if (seenalrm) {
@@ -918,16 +918,18 @@ main(int argc, char *argv[])
timeout = 10;
} else
timeout = INFTIM;
-   fdmaskp[0].fd = s;
-   fdmaskp[0].events = POLLIN;
-   cc = poll(fdmaskp, 1, timeout);
-   if (cc < 0) {
+
+   pfd.fd = s;
+   pfd.events = POLLIN;
+
+   ret = poll(&pfd, 1, timeout);
+   if (ret < 0) {
if (errno != EINTR) {
warn("poll");
sleep(1);
}
continue;
-   } else if (cc == 0)
+   } else if (ret == 0)
continue;
 
m.msg_name = &from;


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: [patch ping.c] replace malloc & memset with calloc

2014-04-23 Thread Jérémie Courrèges-Anglas
Florian Obser  writes:

> On Tue, Apr 22, 2014 at 03:08:45PM -0400, pe...@petermalone.org wrote:
>> Thanks Florian & team.
>> 
>> Please review the following diff.
>
> tab vs. space, more in sync with ping6
> OK?

ok.

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



AI_ADDRCONFIG

2014-04-23 Thread Simon Perreault

(I sent this diff to Éric Faurot on the 12th, but received no reply.)

Tech,

While everyone's having fun removing code from OpenSSL, I decided to add 
some to libasr. I implemented AI_ADDRCONFIG, a getaddrinfo() flag 
defined in RFC 2553/3493. Basically, it tells getaddrinfo() to skip IPvX 
lookups when there are no IPvX addresses configured on any interface. It 
is present on most other OSes. Tons of software out there have to play 
Autoconf games to cope with its absence (which, on OpenBSD, predates 
libasr if I'm not mistaken).


Noteworthy:

- I call getifaddrs() from getaddrinfo_run_async(). This should not 
block, so no need to change the state machine.


- I added AI_ADDRCONFIG to the default hints, like glibc does, and as 
was specified in RFC 2553. (RFC 3493 says nothing about default flags.)


ok? comments?

Simon


Index: include/netdb.h
===
RCS file: /cvs/src/include/netdb.h,v
retrieving revision 1.31
diff -u -p -r1.31 netdb.h
--- include/netdb.h 15 Sep 2012 00:47:08 -  1.31
+++ include/netdb.h 12 Apr 2014 17:40:38 -
@@ -167,9 +167,11 @@ extern int h_errno;
 #define AI_EXT 8   /* enable non-portable extensions */
 #define AI_NUMERICSERV 16  /* don't ever try servname lookup */
 #define AI_FQDN32  /* return the FQDN that was resolved */
+#define AI_ADDRCONFIG  64  /* return configured address families only */
 /* valid flags for addrinfo */
 #define AI_MASK \
-(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | 
AI_FQDN)
+(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | 
AI_FQDN | \

+ AI_ADDRCONFIG)

 #define NI_NUMERICHOST 1   /* return the host address, not the name */
 #define NI_NUMERICSERV 2   /* return the service address, not the name */
Index: lib/libc/asr/getaddrinfo_async.c
===
RCS file: /cvs/src/lib/libc/asr/getaddrinfo_async.c,v
retrieving revision 1.26
diff -u -p -r1.26 getaddrinfo_async.c
--- lib/libc/asr/getaddrinfo_async.c26 Mar 2014 18:13:15 -  1.26
+++ lib/libc/asr/getaddrinfo_async.c12 Apr 2014 17:40:39 -
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef YP
 #include 
 #include 
@@ -32,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include  /* for res_hnok */
 #include 
 #include 
@@ -104,6 +106,7 @@ getaddrinfo_async(const char *hostname,
else {
memset(&as->as.ai.hints, 0, sizeof as->as.ai.hints);
as->as.ai.hints.ai_family = PF_UNSPEC;
+   as->as.ai.hints.ai_flags = AI_ADDRCONFIG;
}

asr_ctx_unref(ac);
@@ -127,8 +130,9 @@ getaddrinfo_async_run(struct asr_query *
char fqdn[MAXDNAME];
const char  *str;
struct addrinfo *ai;
-   int  i, family, r;
+   int  i, family, r, v4, v6;
FILE*f;
+   struct ifaddrs  *ifa, *ifa0;
union {
struct sockaddr sa;
struct sockaddr_in  sain;
@@ -193,6 +197,44 @@ getaddrinfo_async_run(struct asr_query *
ar->ar_gai_errno = EAI_SERVICE;
async_set_state(as, ASR_STATE_HALT);
break;
+   }
+
+   /* Restrict result set to configured address families */
+   if (ai->ai_flags & AI_ADDRCONFIG) {
+   if (getifaddrs(&ifa0) != 0) {
+   ar->ar_gai_errno = EAI_FAIL;
+   async_set_state(as, ASR_STATE_HALT);
+   break;
+   }
+   v4 = 0;
+   v6 = 0;
+   for (ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next) {
+   if (ifa->ifa_addr->sa_family == PF_INET &&
+   ((struct sockaddr_in *)ifa->ifa_addr)
+   ->sin_addr.s_addr != INADDR_LOOPBACK)
+   v4 = 1;
+   else if (ifa->ifa_addr->sa_family == PF_INET6 &&
+   !IN6_IS_ADDR_LOOPBACK(
+   &((struct sockaddr_in6 *)ifa->ifa_addr)
+   ->sin6_addr) &&
+   !((ifa->ifa_flags & IFF_LOOPBACK) &&
+   IN6_IS_ADDR_LINKLOCAL(
+   &((struct sockaddr_in6 *)ifa->ifa_addr)
+   ->sin6_addr)))
+   v6 = 1;
+   }
+   freeifaddrs(ifa0);
+   if (ai->ai_family == PF_UNSPEC && !v4 && !v6 ||
+   ai->ai_family == PF_INET && !v4 ||
+   ai->ai_family == PF_INET6 && 

Re: [patch complete.c] "never read" variables

2014-04-23 Thread Jérémie Courrèges-Anglas
Fritjof Bornebusch  writes:

> Hi tech,
>
> matchlen = 0; is never used.

Committed, thanks.

> Fritjof
>
> Index: complete.c
> ===
> RCS file: /cvs/src/usr.bin/ftp/complete.c,v
> retrieving revision 1.26
> diff -u -p -r1.26 complete.c
> --- complete.c  26 Apr 2010 16:51:59 -  1.26
> +++ complete.c  22 Apr 2014 23:27:47 -
> @@ -90,7 +90,6 @@ complete_ambiguous(char *word, int list,
> }
>  
> if (!list) {
> -   matchlen = 0;
> lastmatch = words->sl_str[0];
> matchlen = strlen(lastmatch);
> for (i = 1 ; i < words->sl_cur ; i++) {
>

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: bpf(4) obsolete data-link levels

2014-04-23 Thread Henning Brauer
* Jérémie Courrèges-Anglas  [2014-04-23 02:05]:
> If I'm not mistaken, we had no drivers left that use those types?

correct, swing the burning axe. ok.

> - case DLT_FDDI:
> - case DLT_ATM_RFC1483:

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services GmbH, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



Re: [PATCH| zero a freed pointer passed in a struct, to prevent reuse after free

2014-04-23 Thread Dirk Engling
On 23.04.14 07:42, patrick keshishian wrote:

> Why not kill the 'if (ret->name != NULL)' check while at it?

I am currently working on a patch that removes all superflous NULL
checks before every free function throughout libressl. There will be a
single commit fixing this.

  erdgeist



Re: [patch ping.c] replace malloc & memset with calloc

2014-04-23 Thread Florian Obser
On Tue, Apr 22, 2014 at 03:08:45PM -0400, pe...@petermalone.org wrote:
> Thanks Florian & team.
> 
> Please review the following diff.

tab vs. space, more in sync with ping6
OK?

diff --git ping.c ping.c
index 6a13a86..29cf84c 100644
--- ping.c
+++ ping.c
@@ -70,6 +70,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -175,11 +176,12 @@ void usage(void);
 int
 main(int argc, char *argv[])
 {
-   struct timeval timeout;
struct hostent *hp;
struct sockaddr_in *to;
+   struct pollfd fdmaskp[1];
struct in_addr saddr;
int i, ch, hold = 1, packlen, preload, maxsize, df = 0, tos = 0;
+   int timeout;
u_char *datap, *packet, ttl = MAXTTL, loop = 1;
char *target, hnamebuf[MAXHOSTNAMELEN];
 #ifdef IP_OPTIONS
@@ -187,8 +189,6 @@ main(int argc, char *argv[])
 #endif
socklen_t maxsizelen;
const char *errstr;
-   fd_set *fdmaskp;
-   size_t fdmasks;
uid_t uid;
u_int rtableid;
 
@@ -507,10 +507,6 @@ main(int argc, char *argv[])
if ((options & F_FLOOD) == 0)
catcher(0); /* start things going */
 
-   fdmasks = howmany(s+1, NFDBITS) * sizeof(fd_mask);
-   if ((fdmaskp = (fd_set *)malloc(fdmasks)) == NULL)
-   err(1, "malloc");
-
for (;;) {
struct sockaddr_in from;
sigset_t omask, nmask;
@@ -519,14 +515,20 @@ main(int argc, char *argv[])
 
if (options & F_FLOOD) {
pinger();
-   timeout.tv_sec = 0;
-   timeout.tv_usec = 1;
-   memset(fdmaskp, 0, fdmasks);
-   FD_SET(s, fdmaskp);
-   if (select(s + 1, (fd_set *)fdmaskp, (fd_set *)NULL,
-   (fd_set *)NULL, &timeout) < 1)
-   continue;
-   }
+   timeout = 10;
+   } else
+   timeout = INFTIM;
+   fdmaskp[0].fd = s;
+   fdmaskp[0].events = POLLIN;
+   cc = poll(fdmaskp, 1, timeout);
+   if (cc < 0) {
+   if (errno != EINTR) {
+   warn("poll");
+   sleep(1);
+   }
+   continue;
+   } else if (cc == 0)
+   continue;
fromlen = sizeof(from);
if ((cc = recvfrom(s, packet, packlen, 0,
(struct sockaddr *)&from, &fromlen)) < 0) {
@@ -543,7 +545,6 @@ main(int argc, char *argv[])
if (npackets && nreceived >= npackets)
break;
}
-   free(fdmaskp);
finish(0);
/* NOTREACHED */
exit(0);/* Make the compiler happy */


-- 
I'm not entirely sure you are real.