[PATCH] lib: fwts_framework: ensure we don't truncate null names
Keng-Yu Lin
kengyu at canonical.com
Mon May 20 07:37:30 UTC 2013
On Tue, May 7, 2013 at 5:10 PM, Colin King <colin.king at canonical.com> 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;
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>
More information about the fwts-devel
mailing list