From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Warren Date: Wed, 16 Jan 2008 15:47:22 -0500 Subject: [U-Boot-Users] [PATCH] TFTP: add host ip addr support In-Reply-To: <20080116204025.C2919242EC@gemini.denx.de> References: <20080116204025.C2919242EC@gemini.denx.de> Message-ID: <478E6D5A.4070807@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Wolfgang Denk wrote: > In message <478E68C6.8070309@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 > > #define MAX_LEN 80 static char tftp_filename[MAX_LEN + 1]; memset(tftp_filename[MAX_LEN], 0, 1); strncpy(tftp_filename, str, MAX_LEN); Better? regards, Ben