ACK: [PATCH] lib: fwts_framework: ensure we don't truncate null names

Alex Hung alex.hung at canonical.com
Thu May 9 05:47:33 UTC 2013


On 05/07/2013 05:10 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Coverity CID #997295: Dereference after null check
>
> minor_test->name may be null, so the call
> fwts_framework_strtrunc(namebuf, minor_test->name, sizeof(namebuf))
> can cause problems.  Make fwts_framework_strtrunc handle null strings.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_framework.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 857b54e..adb46c8 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -291,7 +291,10 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
>    */
>   static void fwts_framework_strtrunc(char *dest, const char *src, size_t max)
>   {
> -	strncpy(dest, src, max);
> +	if (src)
> +		strncpy(dest, src, max);
> +	else
> +		strncpy(dest, "", max);
>
>   	if ((strlen(src) > max) && (max > 3)) {
>   		dest[max-1] = 0;
>
Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list