All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>,
	Frederic Weisbecker <fweisbec@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] kernel: tsacct: strncpy, always be sure of NUL terminated.
Date: Mon, 08 Apr 2013 11:27:08 +0800	[thread overview]
Message-ID: <5162390C.5060804@asianux.com> (raw)


  for NUL terminated string, always set '\0' at the end.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/tsacct.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index a1dd9a1..01bcc4e 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -78,7 +78,8 @@ void bacct_add_tsk(struct user_namespace *user_ns,
 	stats->ac_minflt = tsk->min_flt;
 	stats->ac_majflt = tsk->maj_flt;
 
-	strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm));
+	strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm) - 1);
+	stats->ac_comm[sizeof(stats->ac_comm) - 1] = '\0';
 }
 
 
-- 
1.7.7.6

             reply	other threads:[~2013-04-08  3:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08  3:27 Chen Gang [this message]
2013-04-08  3:52 ` [PATCH] kernel: tsacct: strncpy, always be sure of NUL terminated KOSAKI Motohiro
2013-04-08  4:03   ` Chen Gang

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=5162390C.5060804@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=ebiederm@xmission.com \
    --cc=fweisbec@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.