public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Maier" <balagi@justmail.de>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, gregkh@suse.de
Subject: [PATCH] 2.6.19-rc2-mm2 sysfs: sysfs_write_file() writes zero terminated data
Date: Sun, 22 Oct 2006 19:17:47 +0200	[thread overview]
Message-ID: <op.tht1yneaiudtyh@master> (raw)

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

Hello,

since most of the files in sysfs are text files,
it would be nice, if the "store" function called
during sysfs_write_file() gets a zero terminated
string / data.
The current implementation seems not to ensure this.
(But only if it is the first time the zeroed buffer
page is allocated.)

So the buffer can be scanned by sscanf() easily,
for example.

This patch simply sets a \0 char behind the
data in buffer->page.

Signed-off-by: Thomas Maier <balagi@justmail.de>

[-- Attachment #2: sysfs_write_file-zero-term-string.patch --]
[-- Type: application/octet-stream, Size: 611 bytes --]

diff -urpN linux-2.6.19-rc2-mm2.sysfs/fs/sysfs/file.c 2-sysfs_write_file-string/fs/sysfs/file.c
--- linux-2.6.19-rc2-mm2.sysfs/fs/sysfs/file.c	2006-10-22 18:38:47.000000000 +0200
+++ 2-sysfs_write_file-string/fs/sysfs/file.c	2006-10-22 18:45:38.000000000 +0200
@@ -195,6 +195,9 @@ fill_write_buffer(struct sysfs_buffer * 
 		count = PAGE_SIZE - 1;
 	error = copy_from_user(buffer->page,buf,count);
 	buffer->needs_read_fill = 1;
+	/* if buf is assumed to contain a string, terminate it by \0,
+	   so e.g. sscanf() can scan the string easily */
+	buffer->page[count] = 0;
 	return error ? -EFAULT : count;
 }
 

             reply	other threads:[~2006-10-22 17:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-22 17:17 Thomas Maier [this message]
2006-10-22 18:39 ` [PATCH] 2.6.19-rc2-mm2 sysfs: sysfs_write_file() writes zero terminated data Greg KH
2006-10-23 20:02   ` Thomas Maier
2006-10-23 21:18     ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2006-10-26 12:08 balagi

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=op.tht1yneaiudtyh@master \
    --to=balagi@justmail.de \
    --cc=akpm@osdl.org \
    --cc=gregkh@suse.de \
    --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