[PATCH 1/2] cpu: microcode: ensure we don't overflow with strncpy

Keng-Yu Lin kengyu at canonical.com
Thu Nov 8 05:53:18 UTC 2012


On Wed, Nov 7, 2012 at 12:19 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/cpu/microcode/microcode.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/cpu/microcode/microcode.c b/src/cpu/microcode/microcode.c
> index 50b19e1..7d9a607 100644
> --- a/src/cpu/microcode/microcode.c
> +++ b/src/cpu/microcode/microcode.c
> @@ -75,7 +75,8 @@ static void gather_info(fwts_framework *fw, fwts_list *cpus)
>                                         fwts_log_error(fw, "Cannot allocate memory.");
>                                         break;
>                                 }
> -                               strncpy(cpu->cpu, entry->d_name, 16);
> +                               strncpy(cpu->cpu, entry->d_name, sizeof(cpu->cpu) - 1);
> +                               cpu->cpu[sizeof(cpu->cpu) - 1] = '\0';
>                                 cpu->version = strtoul(data, NULL, 16);
>                                 free(data);
>                                 fwts_list_append(cpus, cpu);
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list