From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Finn Thain <fthain@telegraphics.com.au>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
linux-fsdevel@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH v2 0/6] scsi: Some seq_file cleanups/optimizations
Date: Thu, 29 Jan 2015 10:16:16 +0100 [thread overview]
Message-ID: <87wq46aqvz.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <alpine.LNX.2.00.1501291636140.7510@nippy.intranet> (Finn Thain's message of "Thu, 29 Jan 2015 17:56:37 +1100 (AEDT)")
On Thu, Jan 29 2015, Finn Thain <fthain@telegraphics.com.au> wrote:
> I have one reservation about this patch series.
>
> For example, the changes,
>
> - seq_printf(m, "%s", p);
> + seq_puts(m, p);
>
> These calls are not equivalent because the bounds check is not the same.
> seq_puts will fail when m->count + strlen(p) == m->size.
>
So will seq_printf:
int seq_vprintf(struct seq_file *m, const char *f, va_list args)
{
int len;
if (m->count < m->size) {
len = vsnprintf(m->buf + m->count, m->size - m->count, f, args);
if (m->count + len < m->size) {
m->count += len;
return 0;
}
}
seq_set_overflow(m);
return -1;
}
The return value from vsnprintf("%s", p) is by definition the length of
the string p. Yes, vsnprintf may write some of the bytes from the
string to the buffer, but those are effectively discarded if they don't
all fit, since m->count is not updated.
> There's a similar situation with the changes,
>
> - seq_puts(m, "x");
> + seq_putc(m, 'x');
It's true that this may cause 'x' to be printed which it might not have
been before. I think this is a bug in seq_puts - it should use <= for
its bounds check. OTOH, seq_printf probably needs to continue using <,
because if the return value is == m->size-m->count, vsnprintf will have
truncated the output, overwriting the last byte with a '\0'.
> Have you considered what the implications might be? Are there any?
I must admit I hadn't thought that deeply about it before, but now it
seems that my patches can only end up utilizing m->buf a bit better
(well, 8 bits, to be precise). If I understand the whole seq_*
interface, overflow will just cause a larger buffer to be allocated and
all the print functions to be called again.
Steven, you've been doing some cleanup in this area, among other things
trying to make all the seq_* functions return void. Could you fill me in
on the status of that?
Rasmus
next prev parent reply other threads:[~2015-01-29 9:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-29 0:34 [PATCH 0/7] " Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 1/7] scsi: Remove SPRINTF macro Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 2/7] scsi/g_NCR5380: Remove obfuscating macros Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 3/7] scsi/advansys: Replace seq_printf with seq_puts Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 4/7] scsi/aha152x: " Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 5/7] scsi: misc: " Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 6/7] scsi: misc: Merge consecutive seq_puts calls Rasmus Villemoes
2014-11-29 0:34 ` [PATCH 7/7] scsi: misc: Print single-character strings with seq_putc Rasmus Villemoes
2014-11-30 6:40 ` [PATCH 0/7] scsi: Some seq_file cleanups/optimizations Finn Thain
2014-12-02 23:10 ` [PATCH v2 0/6] " Rasmus Villemoes
2014-12-02 23:10 ` [PATCH v2 1/6] scsi: Remove SPRINTF macro Rasmus Villemoes
2015-01-30 1:37 ` Finn Thain
2014-12-02 23:10 ` [PATCH v2 2/6] scsi/advansys: Replace seq_printf with seq_puts Rasmus Villemoes
2015-01-30 1:38 ` Finn Thain
2014-12-02 23:10 ` [PATCH v2 3/6] scsi/aha152x: " Rasmus Villemoes
2015-01-30 1:40 ` Finn Thain
2014-12-02 23:10 ` [PATCH v2 4/6] scsi: misc: " Rasmus Villemoes
2015-01-30 1:41 ` Finn Thain
2014-12-02 23:10 ` [PATCH v2 5/6] scsi: misc: Merge consecutive seq_puts calls Rasmus Villemoes
2015-01-30 1:42 ` Finn Thain
2014-12-02 23:10 ` [PATCH v2 6/6] scsi: misc: Print single-character strings with seq_putc Rasmus Villemoes
2015-01-30 1:44 ` Finn Thain
2015-01-21 12:08 ` [PATCH v2 0/6] scsi: Some seq_file cleanups/optimizations Rasmus Villemoes
2015-01-29 6:56 ` Finn Thain
2015-01-29 9:16 ` Rasmus Villemoes [this message]
2015-01-29 14:22 ` Steven Rostedt
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=87wq46aqvz.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=JBottomley@parallels.com \
--cc=fthain@telegraphics.com.au \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®