From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerry Van Baren Date: Sat, 06 Dec 2008 21:53:02 -0500 Subject: [U-Boot] [PATCH] common: nvedit to protect additional ethernet addresses Part 1/1 In-Reply-To: <20081207004345.49FCF834B020@gemini.denx.de> References: <4937cd00.hX/ek4tggr3wX3a8%stefan.althoefer@web.de> <49384204.1070901@ge.com> <20081207004345.49FCF834B020@gemini.denx.de> Message-ID: <493B3A8E.1010902@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: > Dear Stefan Althoefer, > > In message you wrote: >> This patches cmd_nvedit to reject changes for "ethaddr." in addition to "ethaddr" >> and "serial#". This is intendend to protect changes to additional ethernet >> addresses (e.g. "ethernet1"). > > The patch is bogus, as additional ethernet addrssses are eth1addr, > eth2addr, etc. and not ethaddr1, etc. > > > Also, please don't remove perfectly god comments. > > NAK. > > Best regards, > > Wolfgang Denk Arrgh, I was thinking I was so clever with strncmp() and it turns out I was being clever based on a totally bogus assumption (wrong format). :-( I *hate* it when that happens. The following should work for eth[0-9]+addr (untested): int ethnum; : : /* "eth[0-9]+addr" is always protected */ if ((sscanf(name, "eth%daddr", ðnum) == 1) && (ethnum < MAX_ETH_ADDRS)) protected = 1; Notes: * The "ethaddr" case is handled prior to the above snippet of code. * I took out the added check "if (strlen (name) == 8)", I'm not sure why that was in there, it would limit us to 10 ethernets. If extra validation is desired, ethnum could be checked to be less than MAX_ETH_ADDRS. On reflection, it seems like a good idea so I added it above. * This is somewhat better than the strncmp() trick because the sscanf() will only convert digits. gvb