[dm-devel] [PATCH v2] hex2bin: fix access beyond string end

Mikulas Patocka mpatocka at redhat.com
Wed Apr 27 14:10:06 UTC 2022



On Wed, 27 Apr 2022, Andy Shevchenko wrote:

> On Tue, Apr 26, 2022 at 5:29 PM Mikulas Patocka <mpatocka at redhat.com> wrote:
> > On Tue, 26 Apr 2022, Andy Shevchenko wrote:
> > > On Tue, Apr 26, 2022 at 08:07:44AM -0400, Mikulas Patocka wrote:
> > > > On Tue, 26 Apr 2022, Andy Shevchenko wrote:
> > > > > On Sun, Apr 24, 2022 at 10:48 PM Mikulas Patocka <mpatocka at redhat.com> wrote:
> 
> ...
> 
> > > Still shadows error codes.
> > >
> > > > +                   return -EINVAL;
> > >
> > > >                     return -EINVAL;
> >
> > What do you mean? What's wrong with "return -EINVAL"?
> 
> The actual error code is returned by hex_to_bin(). What is the point
> of shadowing it with the explicit value?

hex_to_bin returns -1 on error, hex2bin returns -EINVAL on error.

This is inconsistent and it may be fixed (after verifying all the 
hex_to_bin callers - a quick grep over the source shows that there is "if 
((k = hex_to_bin(in_str[j--])) != -1)").

But for the purpose of fixing this bug, we should preserve the behavior 
and return -1 and -EINVAL just like it was before.

Mikulas


More information about the dm-devel mailing list