diff mbox

[U-Boot,v3,1/4] mkexynosspl: fix uninitialized buffer

Message ID 1386608961-15503-1-git-send-email-albert.u.boot@aribaud.net
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Albert ARIBAUD Dec. 9, 2013, 5:09 p.m. UTC
mkexynos reads its input file which might be smaller than
its read buffer, but always writes the whole buffer out.
This does not affect the functionalyty of the output file,
but it makes its content unpredictable as the end of the
buffer is never initialized. Fix this by zeroing the buffer
before reading the input file.

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
Changes in v3:
- fixed mkexynosspl uninitialized buffer

Changes in v2: None

 tools/mkexynosspl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Albert ARIBAUD Dec. 13, 2013, 9 a.m. UTC | #1
(adding Minkyu as the Samsung custodian)

On Mon,  9 Dec 2013 18:09:18 +0100, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:

> mkexynos reads its input file which might be smaller than

( typo: s/mkexynos/mkexynosspl/ -- wil fix when applying if thee is
no other change to be made )

> its read buffer, but always writes the whole buffer out.
> This does not affect the functionalyty of the output file,
> but it makes its content unpredictable as the end of the
> buffer is never initialized. Fix this by zeroing the buffer
> before reading the input file.

Minkyu: should the buffer be pre-filled with zeroes or should I use
ones instead? Or maybe the output could be truncated to the size of the
input?

Amicalement,
Albert.
 
> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> Changes in v3:
> - fixed mkexynosspl uninitialized buffer
> 
> Changes in v2: None
> 
>  tools/mkexynosspl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/mkexynosspl.c b/tools/mkexynosspl.c
> index ef685b7..8d605fa 100644
> --- a/tools/mkexynosspl.c
> +++ b/tools/mkexynosspl.c
> @@ -72,6 +72,8 @@ int main(int argc, char **argv)
>  
>  	count = (len < CHECKSUM_OFFSET) ? len : CHECKSUM_OFFSET;
>  
> +	memset(buffer, 0, BUFSIZE);
> +
>  	if (read(ifd, buffer, count) != count) {
>  		fprintf(stderr, "%s: Can't read %s: %s\n",
>  			argv[0], argv[1], strerror(errno));
Minkyu Kang Dec. 14, 2013, 5:07 a.m. UTC | #2
Dear Albert,

On 13/12/13 18:00, Albert ARIBAUD wrote:
> (adding Minkyu as the Samsung custodian)
> 
> On Mon,  9 Dec 2013 18:09:18 +0100, Albert ARIBAUD
> <albert.u.boot@aribaud.net> wrote:
> 
>> mkexynos reads its input file which might be smaller than
> 
> ( typo: s/mkexynos/mkexynosspl/ -- wil fix when applying if thee is
> no other change to be made )
> 
>> its read buffer, but always writes the whole buffer out.
>> This does not affect the functionalyty of the output file,
>> but it makes its content unpredictable as the end of the
>> buffer is never initialized. Fix this by zeroing the buffer
>> before reading the input file.
> 
> Minkyu: should the buffer be pre-filled with zeroes or should I use
> ones instead? Or maybe the output could be truncated to the size of the
> input?

Basically, the output file is fixed to 14K as same as buffer size.
And the input file should be smaller than 14K.
It's the rule of exynos spl.
The role of mkexynosspl is just adding 4 byte checksum value to end of file.
If the input file is bigger than 14K, output will be truncated.

> 
> Amicalement,
> Albert.
>  
>> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>

btw, this change looks reasonable to me.

Acked-by: Minkyu Kang <mk7.kang@samsung.com>

>> ---
>> Changes in v3:
>> - fixed mkexynosspl uninitialized buffer
>>
>> Changes in v2: None
>>
>>  tools/mkexynosspl.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/mkexynosspl.c b/tools/mkexynosspl.c
>> index ef685b7..8d605fa 100644
>> --- a/tools/mkexynosspl.c
>> +++ b/tools/mkexynosspl.c
>> @@ -72,6 +72,8 @@ int main(int argc, char **argv)
>>  
>>  	count = (len < CHECKSUM_OFFSET) ? len : CHECKSUM_OFFSET;
>>  
>> +	memset(buffer, 0, BUFSIZE);
>> +
>>  	if (read(ifd, buffer, count) != count) {
>>  		fprintf(stderr, "%s: Can't read %s: %s\n",
>>  			argv[0], argv[1], strerror(errno));
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
> 

Thanks,
Minkyu Kang.
Albert ARIBAUD Dec. 14, 2013, 10:14 a.m. UTC | #3
Hi Minkyu,

On Sat, 14 Dec 2013 14:07:57 +0900, Minkyu Kang <mk7.kang@samsung.com>
wrote:

> Dear Albert,
> 
> On 13/12/13 18:00, Albert ARIBAUD wrote:
> > (adding Minkyu as the Samsung custodian)
> > 
> > On Mon,  9 Dec 2013 18:09:18 +0100, Albert ARIBAUD
> > <albert.u.boot@aribaud.net> wrote:
> > 
> >> mkexynos reads its input file which might be smaller than
> > 
> > ( typo: s/mkexynos/mkexynosspl/ -- wil fix when applying if thee is
> > no other change to be made )
> > 
> >> its read buffer, but always writes the whole buffer out.
> >> This does not affect the functionalyty of the output file,

... and s/functionalyty/functionality/, too.

> >> but it makes its content unpredictable as the end of the
> >> buffer is never initialized. Fix this by zeroing the buffer
> >> before reading the input file.
> > 
> > Minkyu: should the buffer be pre-filled with zeroes or should I use
> > ones instead? Or maybe the output could be truncated to the size of the
> > input?
> 
> Basically, the output file is fixed to 14K as same as buffer size.
> And the input file should be smaller than 14K.
> It's the rule of exynos spl.
> The role of mkexynosspl is just adding 4 byte checksum value to end of file.
> If the input file is bigger than 14K, output will be truncated.
> 
> > 
> > Amicalement,
> > Albert.
> >  
> >> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
> 
> btw, this change looks reasonable to me.
> 
> Acked-by: Minkyu Kang <mk7.kang@samsung.com>

Thanks! If that's ok with you, I'll apply 1/4 to ARM, considering it a
kind of bugfix, and remove it from V4 of the patch series if there is
any.

Or if you prefer to apply 1/4 to u-boot-samsung, that's fine with me.

> Thanks,
> Minkyu Kang.

Amicalement,
Minkyu Kang Dec. 16, 2013, 12:48 a.m. UTC | #4
Dear Albert ARIBAUD,

On 14/12/13 19:14, Albert ARIBAUD wrote:
> Hi Minkyu,
> 
> On Sat, 14 Dec 2013 14:07:57 +0900, Minkyu Kang <mk7.kang@samsung.com>
> wrote:
> 
>> Dear Albert,
>>
>> On 13/12/13 18:00, Albert ARIBAUD wrote:
>>> (adding Minkyu as the Samsung custodian)
>>>
>>> On Mon,  9 Dec 2013 18:09:18 +0100, Albert ARIBAUD
>>> <albert.u.boot@aribaud.net> wrote:
>>>
>>>> mkexynos reads its input file which might be smaller than
>>>
>>> ( typo: s/mkexynos/mkexynosspl/ -- wil fix when applying if thee is
>>> no other change to be made )
>>>
>>>> its read buffer, but always writes the whole buffer out.
>>>> This does not affect the functionalyty of the output file,
> 
> ... and s/functionalyty/functionality/, too.
> 
>>>> but it makes its content unpredictable as the end of the
>>>> buffer is never initialized. Fix this by zeroing the buffer
>>>> before reading the input file.
>>>
>>> Minkyu: should the buffer be pre-filled with zeroes or should I use
>>> ones instead? Or maybe the output could be truncated to the size of the
>>> input?
>>
>> Basically, the output file is fixed to 14K as same as buffer size.
>> And the input file should be smaller than 14K.
>> It's the rule of exynos spl.
>> The role of mkexynosspl is just adding 4 byte checksum value to end of file.
>> If the input file is bigger than 14K, output will be truncated.
>>
>>>
>>> Amicalement,
>>> Albert.
>>>  
>>>> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
>>
>> btw, this change looks reasonable to me.
>>
>> Acked-by: Minkyu Kang <mk7.kang@samsung.com>
> 
> Thanks! If that's ok with you, I'll apply 1/4 to ARM, considering it a
> kind of bugfix, and remove it from V4 of the patch series if there is
> any.
> 
> Or if you prefer to apply 1/4 to u-boot-samsung, that's fine with me.

please apply this patch to u-boot-arm.

> 
>> Thanks,
>> Minkyu Kang.
> 
> Amicalement,
> 

Thanks,
Minkyu Kang.
Rajeshwari Birje Dec. 16, 2013, 7:42 a.m. UTC | #5
Hi Albert,

Please refer the following patch:

"SPL: EXYNOS: Prepare for variable size SPL support"

http://patchwork.ozlabs.org/patch/298965/

I don't think after this patch is applied, the above patch would be required.

Regards,
Rajeshwari.


On Mon, Dec 16, 2013 at 6:18 AM, Minkyu Kang <mk7.kang@samsung.com> wrote:
> Dear Albert ARIBAUD,
>
> On 14/12/13 19:14, Albert ARIBAUD wrote:
>> Hi Minkyu,
>>
>> On Sat, 14 Dec 2013 14:07:57 +0900, Minkyu Kang <mk7.kang@samsung.com>
>> wrote:
>>
>>> Dear Albert,
>>>
>>> On 13/12/13 18:00, Albert ARIBAUD wrote:
>>>> (adding Minkyu as the Samsung custodian)
>>>>
>>>> On Mon,  9 Dec 2013 18:09:18 +0100, Albert ARIBAUD
>>>> <albert.u.boot@aribaud.net> wrote:
>>>>
>>>>> mkexynos reads its input file which might be smaller than
>>>>
>>>> ( typo: s/mkexynos/mkexynosspl/ -- wil fix when applying if thee is
>>>> no other change to be made )
>>>>
>>>>> its read buffer, but always writes the whole buffer out.
>>>>> This does not affect the functionalyty of the output file,
>>
>> ... and s/functionalyty/functionality/, too.
>>
>>>>> but it makes its content unpredictable as the end of the
>>>>> buffer is never initialized. Fix this by zeroing the buffer
>>>>> before reading the input file.
>>>>
>>>> Minkyu: should the buffer be pre-filled with zeroes or should I use
>>>> ones instead? Or maybe the output could be truncated to the size of the
>>>> input?
>>>
>>> Basically, the output file is fixed to 14K as same as buffer size.
>>> And the input file should be smaller than 14K.
>>> It's the rule of exynos spl.
>>> The role of mkexynosspl is just adding 4 byte checksum value to end of file.
>>> If the input file is bigger than 14K, output will be truncated.
>>>
>>>>
>>>> Amicalement,
>>>> Albert.
>>>>
>>>>> Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
>>>
>>> btw, this change looks reasonable to me.
>>>
>>> Acked-by: Minkyu Kang <mk7.kang@samsung.com>
>>
>> Thanks! If that's ok with you, I'll apply 1/4 to ARM, considering it a
>> kind of bugfix, and remove it from V4 of the patch series if there is
>> any.
>>
>> Or if you prefer to apply 1/4 to u-boot-samsung, that's fine with me.
>
> please apply this patch to u-boot-arm.
>
>>
>>> Thanks,
>>> Minkyu Kang.
>>
>> Amicalement,
>>
>
> Thanks,
> Minkyu Kang.
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
Albert ARIBAUD Dec. 21, 2013, 9:44 a.m. UTC | #6
Hi Rajeshwari,

On Mon, 16 Dec 2013 13:12:30 +0530, Rajeshwari Birje
<rajeshwari.birje@gmail.com> wrote:

> Hi Albert,
> 
> Please refer the following patch:
> 
> "SPL: EXYNOS: Prepare for variable size SPL support"
> 
> http://patchwork.ozlabs.org/patch/298965/
> 
> I don't think after this patch is applied, the above patch would be required.

Thanks for pointing this out.

Minkyu, have you planned a PR to me with this patch already?

> Regards,
> Rajeshwari.

Amicalement,
Minkyu Kang Dec. 23, 2013, 8:41 a.m. UTC | #7
On 21/12/13 18:44, Albert ARIBAUD wrote:
> Hi Rajeshwari,
> 
> On Mon, 16 Dec 2013 13:12:30 +0530, Rajeshwari Birje
> <rajeshwari.birje@gmail.com> wrote:
> 
>> Hi Albert,
>>
>> Please refer the following patch:
>>
>> "SPL: EXYNOS: Prepare for variable size SPL support"
>>
>> http://patchwork.ozlabs.org/patch/298965/
>>
>> I don't think after this patch is applied, the above patch would be required.
> 
> Thanks for pointing this out.
> 
> Minkyu, have you planned a PR to me with this patch already?

Maybe next weekend?
From tomorrow I'm going to go the winter vacation.

> 
>> Regards,
>> Rajeshwari.
> 
> Amicalement,
> 

Thanks,
Minkyu Kang.
diff mbox

Patch

diff --git a/tools/mkexynosspl.c b/tools/mkexynosspl.c
index ef685b7..8d605fa 100644
--- a/tools/mkexynosspl.c
+++ b/tools/mkexynosspl.c
@@ -72,6 +72,8 @@  int main(int argc, char **argv)
 
 	count = (len < CHECKSUM_OFFSET) ? len : CHECKSUM_OFFSET;
 
+	memset(buffer, 0, BUFSIZE);
+
 	if (read(ifd, buffer, count) != count) {
 		fprintf(stderr, "%s: Can't read %s: %s\n",
 			argv[0], argv[1], strerror(errno));