diff mbox

[U-Boot,2/2] qe: use strncpy instead of strcpy

Message ID 1430812413-7633-2-git-send-email-B45475@freescale.com
State Accepted
Delegated to: York Sun
Headers show

Commit Message

Zhao Qiang May 5, 2015, 7:53 a.m. UTC
strncpy is safer than strcpy, use it to instead of strcpy.

Signed-off-by: Zhao Qiang <B45475@freescale.com>
---
 drivers/qe/qe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Nazzareno Trimarchi May 5, 2015, 8:32 a.m. UTC | #1
Hi

On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com> wrote:
> strncpy is safer than strcpy, use it to instead of strcpy.
>
> Signed-off-by: Zhao Qiang <B45475@freescale.com>
> ---
>  drivers/qe/qe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c
> index f1df0a4..08620b2 100644
> --- a/drivers/qe/qe.c
> +++ b/drivers/qe/qe.c
> @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware *firmware)
>          * saved microcode information and put in the new.
>          */
>         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
> -       strcpy(qe_firmware_info.id, (char *)firmware->id);
> +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);

is 62 somenthing that can be calculated?

>         qe_firmware_info.extended_modes = firmware->extended_modes;
>         memcpy(qe_firmware_info.vtraps, firmware->vtraps,
>                 sizeof(firmware->vtraps));
> --
> 2.1.0.27.g96db324
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
Zhao Qiang May 5, 2015, 9:15 a.m. UTC | #2
On Tue, May 5, 2015 at 4:33 PM, Michael Trimarchi wrote:
> -----Original Message-----
> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
> Sent: Tuesday, May 05, 2015 4:33 PM
> To: Zhao Qiang-B45475
> Cc: u-boot@lists.denx.de; Sun York-R58495
> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
> 
> Hi
> 
> On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com> wrote:
> > strncpy is safer than strcpy, use it to instead of strcpy.
> >
> > Signed-off-by: Zhao Qiang <B45475@freescale.com>
> > ---
> >  drivers/qe/qe.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index f1df0a4..08620b2
> > 100644
> > --- a/drivers/qe/qe.c
> > +++ b/drivers/qe/qe.c
> > @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware
> *firmware)
> >          * saved microcode information and put in the new.
> >          */
> >         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
> > -       strcpy(qe_firmware_info.id, (char *)firmware->id);
> > +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
> 
> is 62 somenthing that can be calculated?

The fireware->id is defined 62 bytes in the struct.


> 
> >         qe_firmware_info.extended_modes = firmware->extended_modes;
> >         memcpy(qe_firmware_info.vtraps, firmware->vtraps,
> >                 sizeof(firmware->vtraps));
> > --
> > 2.1.0.27.g96db324
> >
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot@lists.denx.de
> > http://lists.denx.de/mailman/listinfo/u-boot
Best Regards
Zhao Qiang
Michael Nazzareno Trimarchi May 5, 2015, 9:40 a.m. UTC | #3
Hi

On Tue, May 5, 2015 at 5:15 PM, qiang.zhao@freescale.com
<qiang.zhao@freescale.com> wrote:
> On Tue, May 5, 2015 at 4:33 PM, Michael Trimarchi wrote:
>> -----Original Message-----
>> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
>> Sent: Tuesday, May 05, 2015 4:33 PM
>> To: Zhao Qiang-B45475
>> Cc: u-boot@lists.denx.de; Sun York-R58495
>> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
>>
>> Hi
>>
>> On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com> wrote:
>> > strncpy is safer than strcpy, use it to instead of strcpy.
>> >
>> > Signed-off-by: Zhao Qiang <B45475@freescale.com>
>> > ---
>> >  drivers/qe/qe.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index f1df0a4..08620b2
>> > 100644
>> > --- a/drivers/qe/qe.c
>> > +++ b/drivers/qe/qe.c
>> > @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware
>> *firmware)
>> >          * saved microcode information and put in the new.
>> >          */
>> >         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
>> > -       strcpy(qe_firmware_info.id, (char *)firmware->id);
>> > +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
>>
>> is 62 somenthing that can be calculated?
>
> The fireware->id is defined 62 bytes in the struct.
>

and you don't like sizeof

Michael



>
>>
>> >         qe_firmware_info.extended_modes = firmware->extended_modes;
>> >         memcpy(qe_firmware_info.vtraps, firmware->vtraps,
>> >                 sizeof(firmware->vtraps));
>> > --
>> > 2.1.0.27.g96db324
>> >
>> > _______________________________________________
>> > U-Boot mailing list
>> > U-Boot@lists.denx.de
>> > http://lists.denx.de/mailman/listinfo/u-boot
> Best Regards
> Zhao Qiang
Zhao Qiang May 6, 2015, 1:40 a.m. UTC | #4
On Tue, May 5, 2015 at 5:41 PM, Michael Trimarchi wrote:

> -----Original Message-----
> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
> Sent: Tuesday, May 05, 2015 5:41 PM
> To: Zhao Qiang-B45475
> Cc: u-boot@lists.denx.de; Sun York-R58495
> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
> 
> Hi
> 
> On Tue, May 5, 2015 at 5:15 PM, qiang.zhao@freescale.com
> <qiang.zhao@freescale.com> wrote:
> > On Tue, May 5, 2015 at 4:33 PM, Michael Trimarchi wrote:
> >> -----Original Message-----
> >> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
> >> Sent: Tuesday, May 05, 2015 4:33 PM
> >> To: Zhao Qiang-B45475
> >> Cc: u-boot@lists.denx.de; Sun York-R58495
> >> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
> >>
> >> Hi
> >>
> >> On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com>
> wrote:
> >> > strncpy is safer than strcpy, use it to instead of strcpy.
> >> >
> >> > Signed-off-by: Zhao Qiang <B45475@freescale.com>
> >> > ---
> >> >  drivers/qe/qe.c | 2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index
> >> > f1df0a4..08620b2
> >> > 100644
> >> > --- a/drivers/qe/qe.c
> >> > +++ b/drivers/qe/qe.c
> >> > @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware
> >> *firmware)
> >> >          * saved microcode information and put in the new.
> >> >          */
> >> >         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
> >> > -       strcpy(qe_firmware_info.id, (char *)firmware->id);
> >> > +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
> >>
> >> is 62 somenthing that can be calculated?
> >
> > The fireware->id is defined 62 bytes in the struct.
> >
> 
> and you don't like sizeof

Thank you for your suggestion.
If there are something else need to be modify,
I will use sizeof instead.

> 
> Michael
> 
> 
> 
> >
> >>
> >> >         qe_firmware_info.extended_modes = firmware->extended_modes;
> >> >         memcpy(qe_firmware_info.vtraps, firmware->vtraps,
> >> >                 sizeof(firmware->vtraps));
> >> > --
> >> > 2.1.0.27.g96db324
> >> >
> >> > _______________________________________________
> >> > U-Boot mailing list
> >> > U-Boot@lists.denx.de
> >> > http://lists.denx.de/mailman/listinfo/u-boot
> > Best Regards
> > Zhao Qiang
> 
> 
> 
> --
> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
> | COO  -  Founder                                      Cruquiuskade 47 |
> | +31(0)851119172                                 Amsterdam 1018 AM NL |
> |                  [`as] http://www.amarulasolutions.com               |
Michael Nazzareno Trimarchi May 6, 2015, 5:21 a.m. UTC | #5
Hi

On Wed, May 6, 2015 at 9:40 AM, qiang.zhao@freescale.com
<qiang.zhao@freescale.com> wrote:
> On Tue, May 5, 2015 at 5:41 PM, Michael Trimarchi wrote:
>
>> -----Original Message-----
>> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
>> Sent: Tuesday, May 05, 2015 5:41 PM
>> To: Zhao Qiang-B45475
>> Cc: u-boot@lists.denx.de; Sun York-R58495
>> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
>>
>> Hi
>>
>> On Tue, May 5, 2015 at 5:15 PM, qiang.zhao@freescale.com
>> <qiang.zhao@freescale.com> wrote:
>> > On Tue, May 5, 2015 at 4:33 PM, Michael Trimarchi wrote:
>> >> -----Original Message-----
>> >> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
>> >> Sent: Tuesday, May 05, 2015 4:33 PM
>> >> To: Zhao Qiang-B45475
>> >> Cc: u-boot@lists.denx.de; Sun York-R58495
>> >> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
>> >>
>> >> Hi
>> >>
>> >> On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com>
>> wrote:
>> >> > strncpy is safer than strcpy, use it to instead of strcpy.
>> >> >
>> >> > Signed-off-by: Zhao Qiang <B45475@freescale.com>
>> >> > ---
>> >> >  drivers/qe/qe.c | 2 +-
>> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >> >
>> >> > diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index
>> >> > f1df0a4..08620b2
>> >> > 100644
>> >> > --- a/drivers/qe/qe.c
>> >> > +++ b/drivers/qe/qe.c
>> >> > @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware
>> >> *firmware)
>> >> >          * saved microcode information and put in the new.
>> >> >          */
>> >> >         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
>> >> > -       strcpy(qe_firmware_info.id, (char *)firmware->id);
>> >> > +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
>> >>
>> >> is 62 somenthing that can be calculated?
>> >
>> > The fireware->id is defined 62 bytes in the struct.
>> >
>>
>> and you don't like sizeof
>
> Thank you for your suggestion.
> If there are something else need to be modify,
> I will use sizeof instead.
>

Sorry for boring you ;)

Michael

>>
>> Michael
>>
>>
>>
>> >
>> >>
>> >> >         qe_firmware_info.extended_modes = firmware->extended_modes;
>> >> >         memcpy(qe_firmware_info.vtraps, firmware->vtraps,
>> >> >                 sizeof(firmware->vtraps));
>> >> > --
>> >> > 2.1.0.27.g96db324
>> >> >
>> >> > _______________________________________________
>> >> > U-Boot mailing list
>> >> > U-Boot@lists.denx.de
>> >> > http://lists.denx.de/mailman/listinfo/u-boot
>> > Best Regards
>> > Zhao Qiang
>>
>>
>>
>> --
>> | Michael Nazzareno Trimarchi                     Amarula Solutions BV |
>> | COO  -  Founder                                      Cruquiuskade 47 |
>> | +31(0)851119172                                 Amsterdam 1018 AM NL |
>> |                  [`as] http://www.amarulasolutions.com               |
York Sun June 29, 2015, 6:30 p.m. UTC | #6
On 05/05/2015 06:40 PM, Zhao Qiang-B45475 wrote:
> On Tue, May 5, 2015 at 5:41 PM, Michael Trimarchi wrote:
> 
>> -----Original Message-----
>> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
>> Sent: Tuesday, May 05, 2015 5:41 PM
>> To: Zhao Qiang-B45475
>> Cc: u-boot@lists.denx.de; Sun York-R58495
>> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
>>
>> Hi
>>
>> On Tue, May 5, 2015 at 5:15 PM, qiang.zhao@freescale.com
>> <qiang.zhao@freescale.com> wrote:
>>> On Tue, May 5, 2015 at 4:33 PM, Michael Trimarchi wrote:
>>>> -----Original Message-----
>>>> From: Michael Trimarchi [mailto:michael@amarulasolutions.com]
>>>> Sent: Tuesday, May 05, 2015 4:33 PM
>>>> To: Zhao Qiang-B45475
>>>> Cc: u-boot@lists.denx.de; Sun York-R58495
>>>> Subject: Re: [U-Boot] [PATCH 2/2] qe: use strncpy instead of strcpy
>>>>
>>>> Hi
>>>>
>>>> On Tue, May 5, 2015 at 3:53 PM, Zhao Qiang <B45475@freescale.com>
>> wrote:
>>>>> strncpy is safer than strcpy, use it to instead of strcpy.
>>>>>
>>>>> Signed-off-by: Zhao Qiang <B45475@freescale.com>
>>>>> ---
>>>>>  drivers/qe/qe.c | 2 +-
>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c index
>>>>> f1df0a4..08620b2
>>>>> 100644
>>>>> --- a/drivers/qe/qe.c
>>>>> +++ b/drivers/qe/qe.c
>>>>> @@ -435,7 +435,7 @@ int qe_upload_firmware(const struct qe_firmware
>>>> *firmware)
>>>>>          * saved microcode information and put in the new.
>>>>>          */
>>>>>         memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
>>>>> -       strcpy(qe_firmware_info.id, (char *)firmware->id);
>>>>> +       strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
>>>>
>>>> is 62 somenthing that can be calculated?
>>>
>>> The fireware->id is defined 62 bytes in the struct.
>>>
>>
>> and you don't like sizeof
> 
> Thank you for your suggestion.
> If there are something else need to be modify,
> I will use sizeof instead.

Looks like the id is a null-terminated string. Do you face the same issue as
patch 1/2 in this set? Would it be better to change the type to char?

York
York Sun Aug. 4, 2015, 3:45 p.m. UTC | #7
On 05/05/2015 12:53 AM, Zhao Qiang wrote:
> strncpy is safer than strcpy, use it to instead of strcpy.
> 
> Signed-off-by: Zhao Qiang <B45475@freescale.com>
> ---

Applied to u-boot-fsl-qoriq master. Thanks.

York
diff mbox

Patch

diff --git a/drivers/qe/qe.c b/drivers/qe/qe.c
index f1df0a4..08620b2 100644
--- a/drivers/qe/qe.c
+++ b/drivers/qe/qe.c
@@ -435,7 +435,7 @@  int qe_upload_firmware(const struct qe_firmware *firmware)
 	 * saved microcode information and put in the new.
 	 */
 	memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
-	strcpy(qe_firmware_info.id, (char *)firmware->id);
+	strncpy(qe_firmware_info.id, (char *)firmware->id, 62);
 	qe_firmware_info.extended_modes = firmware->extended_modes;
 	memcpy(qe_firmware_info.vtraps, firmware->vtraps,
 		sizeof(firmware->vtraps));