[U-Boot-Users] [PATCH] TFTP: add host ip addr support
Wolfgang Denk
wd at denx.de
Wed Jan 16 21:40:25 CET 2008
In message <478E68C6.8070309 at gmail.com> you wrote:
>
> > But I diaagree about strncpy because you need to known the size of
> > the string and we know it only when we use the default_filename otherwise
> > we need to strlen and in this strcpy do every thing itself.
> >
> >
> strncpy copies AT MOST 'n' bytes.
...and doesn't necessarily NUL-terminate.
> #define MAX_FILE_NAME_LEN 80
> static char tftp_filename[MAX_FILE_NAME_LEN];
>
> strncpy(tftp_filename, str, MAX_FILE_NAME_LEN);
>
> Standard buffer overrun protection.
...only if you make sure that tftp_filename[] gets terminated
independent of the length; otherwise you fix the problem when writing
the srting but create one when reading it.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Every program has at least one bug and can be shortened by at least
one instruction - from which, by induction, one can deduce that every
program can be reduced to one instruction which doesn't work.
More information about the U-Boot
mailing list