[U-Boot] [PATCH 2/3] GPT: read partition table from device into a data structure

Tom Rini trini at konsulko.com
Fri May 26 12:39:06 UTC 2017


On Sat, May 20, 2017 at 07:27:54PM -0700, alison at peloton-tech.com wrote:

> From: Alison Chaiken <alison at she-devel.com>
> 
> Make the partition table available for modification by reading it from
> the user-specified device into a linked list.   Provide an accessor
> function for command-line testing.
> 
> Signed-off-by: Alison Chaiken <alison at peloton-tech.com>
[snip]
> +	/*
> +	 * 33 rather than 32, as each string must be null-terminated;
> +	 * other extract_val() above will fail.
> +	 */
> +	strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, 33);
> +	strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, 33);

This isn't right.  We have name[32]/type[32] so we're overflowing.  I'm
not quite sure where 32 came from and if we should be defining a name
for it as well.  But to make sure it is null-terminated we should be
here memset'ing after malloc.

> +	newpart->gpt_part_info.bootable = info->bootable;
> +#ifdef CONFIG_PARTITION_UUIDS
> +	strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
> +		UUID_STR_LEN + 1);
> +#endif

Then this should just be copying UUID_STR_LEN over.

> +	if (!valid_parts) {
> +		printf("** No valid partitions found **\n");
> +		del_gpt_info();
> +		return -1;

We should return something from errno here rather than -1.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170526/569fea78/attachment.sig>


More information about the U-Boot mailing list