From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH v1 1/1] lib/string_helpers: Don't copy a tail in kstrdup_and_replace() if 'new' is \0
Date: Thu, 14 Sep 2023 21:37:07 +0300 [thread overview]
Message-ID: <ZQNS0qzJVrRRgNLO@smile.fi.intel.com> (raw)
In-Reply-To: <20230913094557.451463-1-andriy.shevchenko@linux.intel.com>
On Wed, Sep 13, 2023 at 12:45:57PM +0300, Andy Shevchenko wrote:
> The kstrdup_and_replace() takes two characters, old and new, to replace
> former with latter after the copying of the original string. But in case
> when new is a NUL, there is no point to copy the rest of the string,
> the contract with the callers is that that the function returns a
> NUL-terminated string and not a buffer of the size filled with a given
> data. With this we can optimize the memory consumption by copying only
> meaningful part of the original string and drop the rest.
Thinking about this more, I self NAK this.
If the caller knows the size of the original message it can be handy to make
a copy and replace all occurrences of old by NUL. This will be an optimized
implementation of strsep(str, "$OLD").
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2023-09-14 18:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 9:45 [PATCH v1 1/1] lib/string_helpers: Don't copy a tail in kstrdup_and_replace() if 'new' is \0 Andy Shevchenko
2023-09-14 18:37 ` Andy Shevchenko [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=ZQNS0qzJVrRRgNLO@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox