linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@novell.com>
To: linux-numa@vger.kernel.org
Cc: Thomas Renninger <trenn.EMEA5-1.EMEA5@suse.de>
Subject: [PATCH] libnuma: fix memory corruption
Date: Tue, 22 Jun 2010 07:58:51 +0100	[thread overview]
Message-ID: <4C207B4B02000078000078DB@vpn.id2.novell.com> (raw)

Applying strlen() to the result of strncpy() isn't valid...

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Thomas Renninger <trenn@suse.de>

--- 2.0.4-rc2.orig/libnuma.c	2010-04-09 14:25:48.000000000 +0200
+++ 2.0.4-rc2/libnuma.c	2010-06-09 10:22:33.000000000 +0200
@@ -461,10 +461,13 @@ set_task_constraints(void)
 				read_mask(mask, numa_all_nodes_ptr);
 		}
 		if (strncmp(buffer,"Mems_allowed_list:",18) == 0) {
-			nodes_allowed_list = malloc(strlen(buffer)-18);
-			strncpy(nodes_allowed_list, buffer + 19,
-				strlen(buffer) - 19);
-			nodes_allowed_list[strlen(nodes_allowed_list)-1] = '\0';
+			size_t len = strlen(mask);
+
+			nodes_allowed_list = malloc(len);
+			if (nodes_allowed_list) {
+				memcpy(nodes_allowed_list, mask, len-1);
+				nodes_allowed_list[len-1] = '\0';
+			}
 		}
 	}
 	fclose(f);


             reply	other threads:[~2010-06-22  6:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22  6:58 Jan Beulich [this message]
2010-06-22  9:33 ` [PATCH] libnuma: fix memory corruption Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2010-06-22  7:03 Jan Beulich

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=4C207B4B02000078000078DB@vpn.id2.novell.com \
    --to=jbeulich@novell.com \
    --cc=linux-numa@vger.kernel.org \
    --cc=trenn.EMEA5-1.EMEA5@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).