It's more convenient to have strreplace() to return the pointer to
the string itself. This will help users to make their code better.
The patch 1 kills the only user of the returned value of strreplace(),
Patch 2 converts the return value of strreplace(). And patch 3 shows
how it may be useful. That said, the series can be routed via fs tree,
with or without the last patch.
In v2:
- removed not anymore used variable (LKP)
- added tag (Jan)
- fixed wording (Kees)
- actually return the pointer to the string itself
Andy Shevchenko (3):
jbd2: Avoid printing outside the boundary of the buffer
lib/string_helpers: Change returned value of the strreplace()
kobject: Use return value of strreplace()
fs/jbd2/journal.c | 6 ++----
include/linux/string.h | 2 +-
lib/kobject.c | 3 +--
lib/string_helpers.c | 12 ++++++++----
4 files changed, 12 insertions(+), 11 deletions(-)
--
2.40.0.1.gaa8946217a0b
Theoretically possible that "%pg" will take all room for the j_devname
and hence the "-%lu" will go outside the boundary due to unconditional
sprintf() in use. To make this code more robust, replace two sequential
s*printf():s by a single call and then replace forbidden character.
It's possible to do this way, because '/' won't ever be in the result
of "-%lu".
Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
---
fs/jbd2/journal.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 8ae419152ff6..6e17f8f94dfd 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1491,7 +1491,6 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
{
journal_t *journal;
sector_t blocknr;
- char *p;
int err = 0;
blocknr = 0;
@@ -1515,9 +1514,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
journal->j_inode = inode;
snprintf(journal->j_devname, sizeof(journal->j_devname),
- "%pg", journal->j_dev);
- p = strreplace(journal->j_devname, '/', '!');
- sprintf(p, "-%lu", journal->j_inode->i_ino);
+ "%pg-%lu", journal->j_dev, journal->j_inode->i_ino);
+ strreplace(journal->j_devname, '/', '!');
jbd2_stats_proc_init(journal);
return journal;
--
2.40.0.1.gaa8946217a0b
On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
> On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
> > It's more convenient to have strreplace() to return the pointer to
> > the string itself. This will help users to make their code better.
> >
> > The patch 1 kills the only user of the returned value of strreplace(),
> > Patch 2 converts the return value of strreplace(). And patch 3 shows
> > how it may be useful. That said, the series can be routed via fs tree,
> > with or without the last patch.
>
> Since there are no comments, who can apply this (patches 1 and 2)?
> Greg, are you fine with the kobject change?
Sure, want me to take them all through my driver-core tree?
thanks,
greg k-h
On Wed, Apr 05, 2023 at 04:24:42PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
> > On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
> > > It's more convenient to have strreplace() to return the pointer to
> > > the string itself. This will help users to make their code better.
> > >
> > > The patch 1 kills the only user of the returned value of strreplace(),
> > > Patch 2 converts the return value of strreplace(). And patch 3 shows
> > > how it may be useful. That said, the series can be routed via fs tree,
> > > with or without the last patch.
> >
> > Since there are no comments, who can apply this (patches 1 and 2)?
> > Greg, are you fine with the kobject change?
>
> Sure, want me to take them all through my driver-core tree?
Fine by me! Dunno about others. Kees?
--
With Best Regards,
Andy Shevchenko
On April 5, 2023 7:38:40 AM PDT, Andy Shevchenko <[email protected]> wrote:
>On Wed, Apr 05, 2023 at 04:24:42PM +0200, Greg Kroah-Hartman wrote:
>> On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
>> > On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
>> > > It's more convenient to have strreplace() to return the pointer to
>> > > the string itself. This will help users to make their code better.
>> > >
>> > > The patch 1 kills the only user of the returned value of strreplace(),
>> > > Patch 2 converts the return value of strreplace(). And patch 3 shows
>> > > how it may be useful. That said, the series can be routed via fs tree,
>> > > with or without the last patch.
>> >
>> > Since there are no comments, who can apply this (patches 1 and 2)?
>> > Greg, are you fine with the kobject change?
>>
>> Sure, want me to take them all through my driver-core tree?
>
>Fine by me! Dunno about others. Kees?
Yeah, that's cool by me. :)
--
Kees Cook
On Wed, Apr 05, 2023 at 07:58:40PM -0700, Kees Cook wrote:
> On April 5, 2023 7:38:40 AM PDT, Andy Shevchenko <[email protected]> wrote:
> >On Wed, Apr 05, 2023 at 04:24:42PM +0200, Greg Kroah-Hartman wrote:
> >> On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
> >> > On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
> >> > > It's more convenient to have strreplace() to return the pointer to
> >> > > the string itself. This will help users to make their code better.
> >> > >
> >> > > The patch 1 kills the only user of the returned value of strreplace(),
> >> > > Patch 2 converts the return value of strreplace(). And patch 3 shows
> >> > > how it may be useful. That said, the series can be routed via fs tree,
> >> > > with or without the last patch.
> >> >
> >> > Since there are no comments, who can apply this (patches 1 and 2)?
> >> > Greg, are you fine with the kobject change?
> >>
> >> Sure, want me to take them all through my driver-core tree?
> >
> >Fine by me! Dunno about others. Kees?
>
> Yeah, that's cool by me. :)
Greg, does this slip through the cracks?
--
With Best Regards,
Andy Shevchenko
On Mon, Jun 05, 2023 at 05:04:43PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 05, 2023 at 07:58:40PM -0700, Kees Cook wrote:
> > On April 5, 2023 7:38:40 AM PDT, Andy Shevchenko <[email protected]> wrote:
> > >On Wed, Apr 05, 2023 at 04:24:42PM +0200, Greg Kroah-Hartman wrote:
> > >> On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
> > >> > On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
> > >> > > It's more convenient to have strreplace() to return the pointer to
> > >> > > the string itself. This will help users to make their code better.
> > >> > >
> > >> > > The patch 1 kills the only user of the returned value of strreplace(),
> > >> > > Patch 2 converts the return value of strreplace(). And patch 3 shows
> > >> > > how it may be useful. That said, the series can be routed via fs tree,
> > >> > > with or without the last patch.
> > >> >
> > >> > Since there are no comments, who can apply this (patches 1 and 2)?
> > >> > Greg, are you fine with the kobject change?
> > >>
> > >> Sure, want me to take them all through my driver-core tree?
> > >
> > >Fine by me! Dunno about others. Kees?
> >
> > Yeah, that's cool by me. :)
>
> Greg, does this slip through the cracks?
It did. Can someone resend this?
thanks,
greg k-h
On Mon, Jun 05, 2023 at 06:57:48PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Jun 05, 2023 at 05:04:43PM +0300, Andy Shevchenko wrote:
> > On Wed, Apr 05, 2023 at 07:58:40PM -0700, Kees Cook wrote:
> > > On April 5, 2023 7:38:40 AM PDT, Andy Shevchenko <[email protected]> wrote:
> > > >On Wed, Apr 05, 2023 at 04:24:42PM +0200, Greg Kroah-Hartman wrote:
> > > >> On Wed, Apr 05, 2023 at 04:34:31PM +0300, Andy Shevchenko wrote:
> > > >> > On Thu, Mar 23, 2023 at 02:37:01PM +0200, Andy Shevchenko wrote:
> > > >> > > It's more convenient to have strreplace() to return the pointer to
> > > >> > > the string itself. This will help users to make their code better.
> > > >> > >
> > > >> > > The patch 1 kills the only user of the returned value of strreplace(),
> > > >> > > Patch 2 converts the return value of strreplace(). And patch 3 shows
> > > >> > > how it may be useful. That said, the series can be routed via fs tree,
> > > >> > > with or without the last patch.
> > > >> >
> > > >> > Since there are no comments, who can apply this (patches 1 and 2)?
> > > >> > Greg, are you fine with the kobject change?
> > > >>
> > > >> Sure, want me to take them all through my driver-core tree?
> > > >
> > > >Fine by me! Dunno about others. Kees?
> > >
> > > Yeah, that's cool by me. :)
> >
> > Greg, does this slip through the cracks?
>
> It did. Can someone resend this?
Done as v3.
[email protected]
--
With Best Regards,
Andy Shevchenko