All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Nicolas Iooss <nicolas.iooss@m4x.org>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH 1/1] libselinux: ensure strlen() is not called on NULL
Date: Fri, 20 Sep 2019 08:12:01 -0400	[thread overview]
Message-ID: <c4c1f901-5986-92e9-8345-1bf0b62c0ec9@tycho.nsa.gov> (raw)
In-Reply-To: <CAJfZ7==HxzHGkS2e+cJ+qsJaetVgBCv+xQWS0CYdE8yHWEhNwA@mail.gmail.com>

On 9/19/19 4:51 PM, Nicolas Iooss wrote:
> On Thu, Sep 19, 2019 at 6:57 PM Stephen Smalley <sds@tycho.nsa.gov> wrote:
>>
>> On 9/18/19 5:04 PM, Nicolas Iooss wrote:
>>> When compile_regex() calls regex_prepare_data() and this function fails
>>> in the following condition:
>>>
>>>       *regex = regex_data_create();
>>>       if (!(*regex))
>>>           return -1;
>>>
>>> ... error_data has been zero-ed and compile_regex() calls:
>>>
>>>       regex_format_error(&error_data,
>>>           regex_error_format_buffer,
>>>           sizeof(regex_error_format_buffer));
>>>
>>> This leads to a call to strlen(error_data->error_buffer), where
>>> error_data->error_buffer is NULL.
>>>
>>> Avoid this by checking that error_data->error_buffer is not NULL before
>>> calling strlen().
>>
>> It seems like regex_format_error() should just return immediately if
>> !error_data->error_code (#ifdef USE_PCRE2) or !error_data->error_buffer
>> (#ifndef USE_PCRE2), since there is no back-end error message to get and
>> report in that situation.
> 
> I agree. I will modify the patch.
> 
> By the way, while reading function regex_format_error() more
> precisely, something seems strange in:
> 
> pos += rc;
> if (pos >= buf_size)
>      goto truncated;
> if (error_data->error_offset > 0) {
>      /* ... */
> }
> pos += rc;
> 
> As rc is not reset to zero, its value is added twice to pos. Is this a
> bug, or am I misunderstanding something?

I think you are correct - it is a bug.

> 
> Thanks,
> Nicolas
> 


      reply	other threads:[~2019-09-20 12:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18 21:04 [PATCH 1/1] libselinux: ensure strlen() is not called on NULL Nicolas Iooss
2019-09-19 16:57 ` Stephen Smalley
2019-09-19 20:51   ` Nicolas Iooss
2019-09-20 12:12     ` Stephen Smalley [this message]

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=c4c1f901-5986-92e9-8345-1bf0b62c0ec9@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.