From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bill Pringlemeir Date: Wed, 17 Sep 2014 11:25:59 -0400 Subject: [U-Boot] A minor question on a Driver Model function In-Reply-To: <54198F86.3080802@compulab.co.il> (Igor Grinberg's message of "Wed, 17 Sep 2014 16:41:26 +0300") References: <54169D84.9030400@compulab.co.il> <20140917171856.3BCB.AA925319@jp.panasonic.com> <54198F86.3080802@compulab.co.il> Message-ID: <87oauez2t4.fsf@nbsps.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de > On 12 September 2014 05:25, Masahiro Yamada wrote: >>>>> I have a qustion about lists_driver_lookup_name() function. >>>>> for (entry = drv; entry != drv + n_ents; entry++) { >>>>> if (strncmp(name, entry->name, len)) >>>>> continue; >>>>> /* Full match */ >>>>> if (len == strlen(entry->name)) >>>>> return entry; >>>>> } >>> On 09/14/14 21:28, Simon Glass wrote: >>> I would suggest still using strncmp as it is safer, >>> but count also the '\0', so something like: On 17 Sep 2014, grinberg at compulab.co.il wrote: >> Why safer? >> Could you give me more detailed explanation? > On 09/17/14 11:18, Masahiro Yamada wrote: > Well, I'm not an expert in s/w security, but I'll try to explain... [snip] > But, again, I'm not an expert in this area, so its only a suggestion. I thought it was fairly apparent that the current code supports passing a string that is *NOT* null terminated. This can be convenient if you extract a sub-string from a command line and do not need to make a copy that is NULL terminate or perform 'strtok()' type magic. Fwiw, Bill Pringlemeir.