setenv ("bootfile", BootFile);
}
+static int truncate_sz (const char *name, int maxlen, int curlen)
+{
+ if (curlen >= maxlen) {
+ printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
+ name, curlen, maxlen);
+ curlen = maxlen - 1;
+ }
+ return (curlen);
+}
+
#if !(CONFIG_COMMANDS & CFG_CMD_DHCP)
+
static void BootpVendorFieldProcess(u8 *ext)
{
int size = *(ext+1) ;
break;
case 12: /* Host name */
if (NetOurHostName[0] == 0) {
+ size = truncate_sz("Host Name", sizeof(NetOurHostName), size);
memcpy(&NetOurHostName, ext+2, size);
NetOurHostName[size] = 0 ;
}
break;
case 17: /* Root path */
if (NetOurRootPath[0] == 0) {
+ size = truncate_sz("Root Path", sizeof(NetOurRootPath), size);
memcpy(&NetOurRootPath, ext+2, size);
NetOurRootPath[size] = 0 ;
}
/* IP host layer fields */
case 40: /* NIS Domain name */
if (NetOurNISDomain[0] == 0) {
+ size = truncate_sz ("NIS Domain Name",
+ sizeof(NetOurNISDomain),
+ size);
memcpy(&NetOurNISDomain, ext+2, size);
NetOurNISDomain[size] = 0 ;
}
void DhcpOptionsProcess(char *popt)
{
char *end = popt + BOOTP_HDR_SIZE;
- int oplen;
+ int oplen, size;
while ( popt < end && *popt != 0xff ) {
oplen = *(popt + 1);
NetOurDNSIP = *(IPaddr_t *)(popt +2);
break;
case 12:
- memcpy(&NetOurHostName, popt+2, oplen);
- NetOurHostName[oplen] = 0 ;
+ size = truncate_sz ("Host Name",
+ sizeof(NetOurHostName),
+ oplen);
+ memcpy(&NetOurHostName, popt+2, size);
+ NetOurHostName[size] = 0 ;
break;
case 15: /* Ignore Domain Name Option */
break;
case 17:
- memcpy(&NetOurRootPath, popt+2, oplen);
- NetOurRootPath[oplen] = 0 ;
+ size = truncate_sz ("Root Path",
+ sizeof(NetOurRootPath),
+ oplen);
+ memcpy(&NetOurRootPath, popt+2, size);
+ NetOurRootPath[size] = 0 ;
break;
case 51:
dhcp_leasetime = *(unsigned int *)(popt + 2);
IPaddr_t NetOurDNSIP=0; /* Our DNS IP address */
char NetOurNISDomain[32]={0,}; /* Our NIS domain */
char NetOurHostName[32]={0,}; /* Our hostname */
-char NetOurRootPath[32]={0,}; /* Our bootpath */
+char NetOurRootPath[64]={0,}; /* Our bootpath */
ushort NetBootFileSize=0; /* Our bootfile size in blocks */
/** END OF BOOTP EXTENTIONS **/