Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Aug 2006 21:43:59 +0200
From:      Dan Lukes <dan@obluda.cz>
To:        Maxim Konovalov <maxim@FreeBSD.org>
Cc:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/101575: [patch] Memory overflow "off-by one" in hexdump(1)
Message-ID:  <44DA3AFF.1060507@obluda.cz>
In-Reply-To: <200608091914.k79JE3HM045970@freefall.freebsd.org>
References:  <200608091914.k79JE3HM045970@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

	I didn't understand why OpenBSD didn't use this way:

--- current code ---
size_t len;
...
len = strlen(fmtp) + strlen(cs) + 1;
if ((pr->fmt = calloc(1, len)) == NULL)
	err(1, NULL);
snprintf(pr->fmt, len, "%s%s", fmtp, cs);
--- better code ---
asprintf(&pr->fmt, "%s%s", fmtp, cs);
if (pr->fmt == NULL)
	err(1, NULL);
-------------------

	The implementatin of asprintf on FreeBSD come from OpenBSD, so it's 
sure the OpenBSD has this function. This situation is exactly what the 
asprintf is for. In advance, we need no additional variable.

	I think we should wrote nice effective code and allow the OpenBSD learn 
from FreeBSD code. At least sometime. At least when we can wrote better 
code ...

	But, I'm not sure if you are asking me for this kind of opinion.

	Well. Your patch close the reported hole, so it's OK.

						Dan


-- 
Dan Lukes                                   SISAL MFF UK
AKA: dan@obluda.cz, dan@freebsd.cz,dan@kolej.mff.cuni.cz



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44DA3AFF.1060507>