dhcpcd crash on startup (reading options)
Graham Breed
Fri Dec 20 16:06:10 2019
I upgraded dhcpcd and it consistently failed to start up. I tracked the
problem down to a '\0' being added beyond the allocated memory. There's
a simple patch:
> ---
> src/if-options.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/if-options.c b/src/if-options.c
> index f3f12316..6bf4ad04 100644
> --- a/src/if-options.c
> +++ b/src/if-options.c
> @@ -720,7 +720,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
> break;
> }
> dl = (size_t)s;
> - if (s == -1 || (ifo->script = malloc(dl)) == NULL) {
> + if (s == -1 || (ifo->script = malloc(dl + 1)) == NULL) {
> ifo->script = NULL;
> logerr(__func__);
> return -1;
> --
And, if it isn't that simple, at least this works for me. This is the
valgrind warning that pointed me to it:
> ==8231== Invalid write of size 1
> ==8231== at 0x40D674: parse_str (if-options.c:397)
> ==8231== by 0x40E03E: parse_option (if-options.c:728)
> ==8231== by 0x412F0A: parse_config_line (if-options.c:2205)
> ==8231== by 0x413C97: read_config (if-options.c:2559)
> ==8231== by 0x40823F: main (dhcpcd.c:1722)
> ==8231== Address 0x5237758 is 0 bytes after a block of size 24 alloc'd
> ==8231== at 0x4C2DF06: malloc (vg_replace_malloc.c:309)
> ==8231== by 0x40DFC6: parse_option (if-options.c:723)
> ==8231== by 0x412F0A: parse_config_line (if-options.c:2205)
> ==8231== by 0x413C97: read_config (if-options.c:2559)
> ==8231== by 0x40823F: main (dhcpcd.c:1722)
This is dhcpcd 8.1.3 on Linux. Versions back to 7.2.0 have the same
problem.
Graham
--
------------------------------
*Graham Breed*
Systems Developer, ApplianSys
ApplianSys House
Harry Weston Road
Coventry CV3 2UB
www.appliansys.com
*Our sales team sells by referral:*
Less time looking for customers, more time looking after them
ApplianSys Limited registered in England & Wales #: 07608382 at ApplianSys
House, Harry Weston Road, Coventry CV3 2UB
Archive administrator: postmaster@marples.name