public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Bill Pringlemeir <bpringlemeir@nbsps.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] A minor question on a Driver Model function
Date: Thu, 18 Sep 2014 11:46:18 -0400	[thread overview]
Message-ID: <87egv9x779.fsf@nbsps.com> (raw)
In-Reply-To: <541AD248.6000100@compulab.co.il> (Igor Grinberg's message of "Thu, 18 Sep 2014 15:38:32 +0300")


>>> On 12 September 2014 05:25, Masahiro Yamada
>>> <yamada.m@jp.panasonic.com> wrote:
>>
>>>>>>> I have a qustion about lists_driver_lookup_name() function.

>>>>> 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.
>>

> On 09/17/14 18:25, Bill Pringlemeir wrote:

>> 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.

On 18 Sep 2014, grinberg at compulab.co.il wrote:

> Here is the whole function:
>
> ------------------------------cut--------------------------
> struct driver *lists_driver_lookup_name(const char *name)
> {
> struct driver *drv =
> ll_entry_start(struct driver, driver);
> const int n_ents = ll_entry_count(struct driver, driver);
> struct driver *entry;
> int len;
>
> if (!drv || !n_ents)
> return NULL;
>
> len = strlen(name);
>
> for (entry = drv; entry != drv + n_ents; entry++) {
> if (strncmp(name, entry->name, len))
> continue;
>
> /* Full match */
> if (len == strlen(entry->name))
> return entry;
>>
>
> /* Not found */
> return NULL;
>>
> ------------------------------cut--------------------------
>
> and... no, the code does not support passing a string that is
> not null terminated.

Then using the strncmp() seems useless for security reasons?  The 'len'
is not passed in by the caller and 'strlen()' will have the same
problems that 'strcmp()' would for read buffer overflows?  I would guess
the code was cribbed from where 'len' was passed?  In that case, it
would support strings that are not null terminated.

Sorry, I didn't look and understand your query now.

Fwiw,
Bill Pringlemeir.

  reply	other threads:[~2014-09-18 15:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 11:25 [U-Boot] A minor question on a Driver Model function Masahiro Yamada
2014-09-14 18:28 ` Simon Glass
2014-09-15  8:04   ` Igor Grinberg
2014-09-17  8:18     ` Masahiro Yamada
2014-09-17 13:41       ` Igor Grinberg
2014-09-17 15:25         ` Bill Pringlemeir
2014-09-18 12:38           ` Igor Grinberg
2014-09-18 15:46             ` Bill Pringlemeir [this message]
2014-09-19  6:34               ` Igor Grinberg
2014-09-19  6:54                 ` Masahiro Yamada
2014-09-19 13:41                   ` Igor Grinberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egv9x779.fsf@nbsps.com \
    --to=bpringlemeir@nbsps.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox