Re: syslogd: less global, more malloc, more random

2015-09-09 Thread Todd C. Miller
On Wed, 09 Sep 2015 13:14:16 +0200, Alexander Bluhm wrote:

> Instead of having global variables containing the libevent structures,
> allocate them with malloc.  This makes the address space layout
> more random.

That huge if() makes things a bit harder to read.  Doing the NULL
check separately from the calls to malloc() might help.  E.g.

ev_ctlaccept = malloc(sizeof(struct event));
ev_ctlread = malloc(sizeof(struct event));
ev_ctlwrite = malloc(sizeof(struct event));
ev_klog = malloc(sizeof(struct event));
ev_sendsys = malloc(sizeof(struct event));
ev_udp = malloc(sizeof(struct event));
ev_udp6 = malloc(sizeof(struct event));
ev_bind = malloc(sizeof(struct event));
ev_listen = malloc(sizeof(struct event));
ev_unix = reallocarray(NULL, nunix, sizeof(struct event));
ev_hup = malloc(sizeof(struct event));
ev_int = malloc(sizeof(struct event));
ev_quit = malloc(sizeof(struct event));
ev_term = malloc(sizeof(struct event));
ev_mark = malloc(sizeof(struct event));

if (ev_ctlaccept == NULL || ev_ctlread == NULL || ev_ctlwrite == NULL ||
ev_klog == NULL || ev_sendsys == NULL || ev_udp == NULL ||
ev_udp6 == NULL || ev_bind == NULL || ev_int == NULL ||
ev_quit == NULL || ev_term == NULL || ev_mark == NULL)
err(1, "malloc");

 - todd



Re: syslogd: less global, more malloc, more random

2015-09-09 Thread Todd C. Miller
On Wed, 09 Sep 2015 18:57:05 +0200, Alexander Bluhm wrote:

> Hmm, then you have another list where you can forget one of them.
> ev_listen, ev_unix, ev_hup are missing in your example.

Yeah, that is the downside.  Looks like I deleted a little too much.

 - todd



Re: syslogd: less global, more malloc, more random

2015-09-09 Thread Alexander Bluhm
On Wed, Sep 09, 2015 at 08:55:12AM -0600, Todd C. Miller wrote:
> On Wed, 09 Sep 2015 13:14:16 +0200, Alexander Bluhm wrote:
> 
> > Instead of having global variables containing the libevent structures,
> > allocate them with malloc.  This makes the address space layout
> > more random.
> 
> That huge if() makes things a bit harder to read.  Doing the NULL
> check separately from the calls to malloc() might help.  E.g.

Hmm, then you have another list where you can forget one of them.
ev_listen, ev_unix, ev_hup are missing in your example.

bluhm

>   ev_ctlaccept = malloc(sizeof(struct event));
>   ev_ctlread = malloc(sizeof(struct event));
>   ev_ctlwrite = malloc(sizeof(struct event));
>   ev_klog = malloc(sizeof(struct event));
>   ev_sendsys = malloc(sizeof(struct event));
>   ev_udp = malloc(sizeof(struct event));
>   ev_udp6 = malloc(sizeof(struct event));
>   ev_bind = malloc(sizeof(struct event));
>   ev_listen = malloc(sizeof(struct event));
>   ev_unix = reallocarray(NULL, nunix, sizeof(struct event));
>   ev_hup = malloc(sizeof(struct event));
>   ev_int = malloc(sizeof(struct event));
>   ev_quit = malloc(sizeof(struct event));
>   ev_term = malloc(sizeof(struct event));
>   ev_mark = malloc(sizeof(struct event));
> 
>   if (ev_ctlaccept == NULL || ev_ctlread == NULL || ev_ctlwrite == NULL ||
>   ev_klog == NULL || ev_sendsys == NULL || ev_udp == NULL ||
>   ev_udp6 == NULL || ev_bind == NULL || ev_int == NULL ||
>   ev_quit == NULL || ev_term == NULL || ev_mark == NULL)
>   err(1, "malloc");
> 
>  - todd