Re: [Xen-devel] [PATCH 1/2] hvmloader: correctly copy signature to info structures

2016-08-19 Thread Jan Beulich
>>> On 19.08.16 at 11:42,  wrote:
> On 19/08/16 09:25, Jan Beulich wrote:
> On 19.08.16 at 10:06,  wrote:
>>> --- a/tools/firmware/hvmloader/ovmf.c
>>> +++ b/tools/firmware/hvmloader/ovmf.c
>>> @@ -67,10 +67,11 @@ struct ovmf_info {
>>>  static void ovmf_setup_bios_info(void)
>>>  {
>>>  struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
>>> +const char sig[] = "XenHVMOVMF";
>>>  
>>>  memset(info, 0, sizeof(*info));
>>>  
>>> -memcpy(info->signature, "XenHVMOVMF", sizeof(info->signature));
>>> +memcpy(info->signature, sig, sizeof(sig));
>>>  info->length = sizeof(*info);
>>>  }
>> I think using strncpy() would be more natural in cases like this,
>> as it would at once make clear that the destination can't be
>> overrun no matter how large the string literal.
> 
> How about structure assignment?
> 
> *info = (struct ovmf_info) { .signature = "XenHVMOVMF", .length =
> sizeof(*info) }
> 
> which also subsumed the memset()?

Fine with me, albeit maybe a little uglier to read.

Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 1/2] hvmloader: correctly copy signature to info structures

2016-08-19 Thread Andrew Cooper
On 19/08/16 09:25, Jan Beulich wrote:
 On 19.08.16 at 10:06,  wrote:
>> --- a/tools/firmware/hvmloader/ovmf.c
>> +++ b/tools/firmware/hvmloader/ovmf.c
>> @@ -67,10 +67,11 @@ struct ovmf_info {
>>  static void ovmf_setup_bios_info(void)
>>  {
>>  struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
>> +const char sig[] = "XenHVMOVMF";
>>  
>>  memset(info, 0, sizeof(*info));
>>  
>> -memcpy(info->signature, "XenHVMOVMF", sizeof(info->signature));
>> +memcpy(info->signature, sig, sizeof(sig));
>>  info->length = sizeof(*info);
>>  }
> I think using strncpy() would be more natural in cases like this,
> as it would at once make clear that the destination can't be
> overrun no matter how large the string literal.

How about structure assignment?

*info = (struct ovmf_info) { .signature = "XenHVMOVMF", .length =
sizeof(*info) }

which also subsumed the memset()?

~Andrew

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH 1/2] hvmloader: correctly copy signature to info structures

2016-08-19 Thread Jan Beulich
>>> On 19.08.16 at 10:06,  wrote:
> --- a/tools/firmware/hvmloader/ovmf.c
> +++ b/tools/firmware/hvmloader/ovmf.c
> @@ -67,10 +67,11 @@ struct ovmf_info {
>  static void ovmf_setup_bios_info(void)
>  {
>  struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
> +const char sig[] = "XenHVMOVMF";
>  
>  memset(info, 0, sizeof(*info));
>  
> -memcpy(info->signature, "XenHVMOVMF", sizeof(info->signature));
> +memcpy(info->signature, sig, sizeof(sig));
>  info->length = sizeof(*info);
>  }

I think using strncpy() would be more natural in cases like this,
as it would at once make clear that the destination can't be
overrun no matter how large the string literal.

Jan


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel