lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1442319558.8361.33.camel@linux.intel.com>
Date:	Tue, 15 Sep 2015 15:19:18 +0300
From:	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:	Vitaly Kuznetsov <vkuznets@...hat.com>
Cc:	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Andrew Morton <akpm@...ux-foundation.org>,
	James Bottomley <JBottomley@...n.com>,
	linux-kernel@...r.kernel.org,
	"K. Y. Srinivasan" <kys@...rosoft.com>
Subject: Re: [PATCH v3 2/2] lib/test-string_helpers.c: add string_get_size()
 tests

On Tue, 2015-09-15 at 14:10 +0200, Vitaly Kuznetsov wrote:
> Andy Shevchenko <andriy.shevchenko@...ux.intel.com> writes:
> 
> > I prefer to put '\0' at the position after we expected have an
> > actual
> > '\0'. In this case we always be NULL terminated. I did this for 
> > hexdump
> > test cases.
> 
> Just to check I got your suggestions right:
> 
> ...
> +       if (!memcmp(buf, exp_result, strnlen(exp_result, sizeof(buf) 
> - 1) + 1))
> +               return;
> +
> +       /* NULL terminate buf right after the expected '\0' */
> +       buf[strnlen(exp_result, sizeof(buf) - 2) + 1] = '\0';
> ...
> 
> Alternatively, we could have avoided strnlen() by asserting
> strlen(exp_result) < sizeof(buf) - 1 at the very beginning.
> 

Just 

buf[sizeof(buf) - 1] = '\0';

should be enough after you called the string_get_size().

And minimize the buffer to something like 16 (whatever is the biggest
possible length + '\0' + some space for the wrong algorithm aligned to
let's say 4.

-- 
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Intel Finland Oy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ