[Skiboot] [PATCH V6 21/21] core/pldm: Get file handle and file length

Abhishek SIngh Tomar abhishek at linux.ibm.com
Fri Sep 30 22:12:42 AEST 2022


> + * Retrieve the file handle and file length from the file attribute
> + * table.
> + */
> +static int find_file_handle_by_lid_id(const char *lid_id,
...
> +		file_entry = (struct pldm_file_attr_table_entry *)startptr;
> +
> +		*file_handle = le32_to_cpu(file_entry->file_handle);
> +		startptr += sizeof(uint32_t);
> +
> +		file_name_length = le16_to_cpu(file_entry->file_name_length);
> +		startptr += sizeof(file_name_length);
> +
> +		if (!strncmp(startptr, lid_id, strlen(lid_id))) {
> +			startptr += file_name_length;
> +			*file_length = le32_to_cpu(*(uint32_t *)startptr);
> +			break;
> +		}
In above code we compare string using strncmp with n=strlen(lid_id)
This issue maybe rare or impossible to generate but 
	1. if in some case lid_id is substring of strtptr
	2. if strtptr is smaller but comparision concatinate some bytes
	from file_length which make two string equal
As there is no comparision between strlen(lid_id) and file_name_length
Adding comparision between two values can be good practice

Thanks
Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>



More information about the Skiboot mailing list