diff mbox

[U-Boot,v2,20/28] tpm: Check that parse_byte_string() has data to parse

Message ID 1440289904-31280-21-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Aug. 23, 2015, 12:31 a.m. UTC
Rather then crashing when there is no data, print an error.

Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/cmd_tpm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Christophe Ricard Aug. 24, 2015, 8:22 p.m. UTC | #1
Hi Simon,

Print an error ? Are you sure ? I guess the comment is not accurate ;).

Best Regards
Christophe

On 23/08/2015 02:31, Simon Glass wrote:
> Rather then crashing when there is no data, print an error.
>
> Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2: None
>
>   common/cmd_tpm.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
> index 65e7371..e9c6618 100644
> --- a/common/cmd_tpm.c
> +++ b/common/cmd_tpm.c
> @@ -58,6 +58,8 @@ static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
>   	size_t count, length;
>   	int i;
>   
> +	if (!bytes)
> +		return NULL;
>   	length = strlen(bytes);
>   	count = length / 2;
>
Simon Glass Aug. 25, 2015, 4:13 a.m. UTC | #2
Hi Christophe,

On 24 August 2015 at 14:22, Christophe Ricard
<christophe.ricard@gmail.com> wrote:
> Hi Simon,
>
> Print an error ? Are you sure ? I guess the comment is not accurate ;).
>
Well returning NULL from parse_byte_string() will cause an error to be
printed by the caller...

Regards,
Simon

> Best Regards
> Christophe
>
>
> On 23/08/2015 02:31, Simon Glass wrote:
>>
>> Rather then crashing when there is no data, print an error.
>>
>> Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> Changes in v2: None
>>
>>   common/cmd_tpm.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
>> index 65e7371..e9c6618 100644
>> --- a/common/cmd_tpm.c
>> +++ b/common/cmd_tpm.c
>> @@ -58,6 +58,8 @@ static void *parse_byte_string(char *bytes, uint8_t
>> *data, size_t *count_ptr)
>>         size_t count, length;
>>         int i;
>>   +     if (!bytes)
>> +               return NULL;
>>         length = strlen(bytes);
>>         count = length / 2;
>>
>
>
Christophe Ricard Aug. 25, 2015, 6:40 p.m. UTC | #3
Hi Simon,
Le 25/08/2015 06:13, Simon Glass a écrit :
> Hi Christophe,
>
> On 24 August 2015 at 14:22, Christophe Ricard
> <christophe.ricard@gmail.com> wrote:
>> Hi Simon,
>>
>> Print an error ? Are you sure ? I guess the comment is not accurate ;).
>>
> Well returning NULL from parse_byte_string() will cause an error to be
> printed by the caller...

This is just a comment nitpick. I think it is clear enough but from the 
patch the printing is may be not so obvious.
It is just fine like that.
>
> Regards,
> Simon
Best Regards
Christophe
>> Best Regards
>> Christophe
>>
>>
>> On 23/08/2015 02:31, Simon Glass wrote:
>>> Rather then crashing when there is no data, print an error.
>>>
>>> Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>> Changes in v2: None
>>>
>>>    common/cmd_tpm.c | 2 ++
>>>    1 file changed, 2 insertions(+)
>>>
>>> diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
>>> index 65e7371..e9c6618 100644
>>> --- a/common/cmd_tpm.c
>>> +++ b/common/cmd_tpm.c
>>> @@ -58,6 +58,8 @@ static void *parse_byte_string(char *bytes, uint8_t
>>> *data, size_t *count_ptr)
>>>          size_t count, length;
>>>          int i;
>>>    +     if (!bytes)
>>> +               return NULL;
>>>          length = strlen(bytes);
>>>          count = length / 2;
>>>
>>
Simon Glass Aug. 30, 2015, 10:43 p.m. UTC | #4
On 25 August 2015 at 12:40, Christophe Ricard
<christophe.ricard@gmail.com> wrote:
> Hi Simon,
> Le 25/08/2015 06:13, Simon Glass a écrit :
>>
>> Hi Christophe,
>>
>> On 24 August 2015 at 14:22, Christophe Ricard
>> <christophe.ricard@gmail.com> wrote:
>>>
>>> Hi Simon,
>>>
>>> Print an error ? Are you sure ? I guess the comment is not accurate ;).
>>>
>> Well returning NULL from parse_byte_string() will cause an error to be
>> printed by the caller...
>
>
> This is just a comment nitpick. I think it is clear enough but from the
> patch the printing is may be not so obvious.
> It is just fine like that.

OK thanks. I fixed up the commit message to be a bit more explanatory.

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 65e7371..e9c6618 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -58,6 +58,8 @@  static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
 	size_t count, length;
 	int i;
 
+	if (!bytes)
+		return NULL;
 	length = strlen(bytes);
 	count = length / 2;