Re: [PATCH 4/5] lib/string_helpers: use full destination buffer in string_unescape()

From: Andy Shevchenko

Date: Thu Sep 17 2026 - 09:50:14 EST


On Thu, Sep 17, 2026 at 11:02:52AM +0200, Jonas Rebmann wrote:
> On 2026-09-17 09:45, Andy Shevchenko wrote:
> > On Wed, Sep 16, 2026 at 07:38:09PM +0200, Jonas Rebmann wrote:

...

> > > + test_string_unescape_one(test, "short buffer", UNESCAPE_HEX, "\\x41\\x41B", 4, "AAB", 3);
> > > + test_string_unescape_one(test, "unrecognized escape at end", UNESCAPE_HEX, "B\\qX", 4, "B\\q", 3);
> >
> > Still wondering if we can incorporate this into the "combined" loop?
>
> Both these tests really only fail without my fixes because the
> destination buffer is short, barely fitting the result.
>
> With a buffer length of 4 it yields "A\", for 5 "AA" and for 6 "AAB",
> a bug because "AAB" would fit the 4 byte buffer too.

So, we need to extend the current loop to pass the buffer length like -5, -4,
-3, -2, -1, 0, +1 from the expected length and check that it's cut correctly
along with no garbage at the end. It will help all test cases, and not just
a single one or a couple.

--
With Best Regards,
Andy Shevchenko