mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <andrewm@uow.edu.au>
To: Alan Cox <laughing@shared-source.org>, crutcher+kernel@datastacks.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: Linux 2.4.6-ac5
Date: Tue, 17 Jul 2001 01:27:07 +1000	[thread overview]
Message-ID: <3B5307CB.1BA89A6F@uow.edu.au> (raw)
In-Reply-To: <20010716153702.A21514@lightning.swansea.linux.org.uk>

Alan Cox wrote:
> 
> o       Add snprintf/vsnprintf to the kernel            (Crutcher Dunnavant)

Nice.

Couple of things:

+       if (end < buf - 1) {
+               end = ((void *) -1);
+               size = end - buf + 1;
+       }

This is odd.  It seems to be saying that if we're trying to
wrap around the end of memory, we terminate at the end of
memory, yes?  What is the intent here?


Also, my manpage says that vsnprintf should return -1
if it truncated the output.  Your implementation
doesn't do that, but trivially could.

Alan, we can drop the overrun-detector from printk now.

--- linux-2.4.6-ac5/kernel/printk.c	Tue Jul 17 00:59:21 2001
+++ ac/kernel/printk.c	Tue Jul 17 01:22:59 2001
@@ -394,11 +394,7 @@ asmlinkage int printk(const char *fmt, .
 	unsigned long flags;
 	int printed_len;
 	char *p;
-	unsigned long sr_copy;
-	static struct {
-		char buf[1024];
-		unsigned long semi_random;
-	} printk_buf;
+	static char printk_buf[1024];
 	static int log_level_unknown = 1;
 
 	if (oops_in_progress) {
@@ -412,19 +408,20 @@ asmlinkage int printk(const char *fmt, .
 	spin_lock_irqsave(&logbuf_lock, flags);
 
 	/* Emit the output into the temporary buffer */
-	printk_buf.semi_random += jiffies;
-	sr_copy = printk_buf.semi_random;
 	va_start(args, fmt);
-	printed_len = vsprintf(printk_buf.buf, fmt, args);
+	printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
+	if (printed_len == -1) {
+		/* vsnprintf truncated it, but printk() callers don't
+		 * expect a -1 return value */
+		printed_len = sizeof(printk_buf) - 1;
+	}
 	va_end(args);
-	if (sr_copy != printk_buf.semi_random)
-		panic("buffer overrun in printk()");
 
 	/*
 	 * Copy the output into log_buf.  If the caller didn't provide
 	 * appropriate log level tags, we insert them here
 	 */
-	for (p = printk_buf.buf; *p; p++) {
+	for (p = printk_buf; *p; p++) {
 		if (log_level_unknown) {
 			if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') {
 				emit_log_char('<');

  reply	other threads:[~2001-07-16 15:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-16 14:37 Alan Cox
2001-07-16 15:27 ` Andrew Morton [this message]
2001-07-16 15:43 ` Jonathan Lundell

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=3B5307CB.1BA89A6F@uow.edu.au \
    --to=andrewm@uow.edu.au \
    --cc=crutcher+kernel@datastacks.com \
    --cc=laughing@shared-source.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

all inboxes | Powered by JetHome®