On Tue, Jan 19, 2021 at 01:19:42PM +0800, Feng Tang wrote:
> Sorry, after testing on more platforms, the following is needed to fix
> a potential array overflow ((a full patch with fix is also attached)
> 
> diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c
> index 3ea607b..bf68335 100644
> --- a/tools/arch/x86/kcpuid/kcpuid.c
> +++ b/tools/arch/x86/kcpuid/kcpuid.c
> @@ -329,7 +329,8 @@ static int parse_line(char *line)
>               range = leafs_basic;
>  
>       index &= 0x7FFFFFFF;
> -     if ((int)index > range->nr)
> +     /* range->nr equals to max index plus 1 */
> +     if ((int)index >= range->nr)

That comment is basically repeating the code. What it should do is
explain *why* that test is being done or not be there at all.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Reply via email to