From 737352893a49e225daf6d3fda033c678ad83d8c9 Mon Sep 17 00:00:00 2001 From: Ryota Ozaki Date: Wed, 25 Apr 2012 11:03:39 +1000 Subject: [PATCH] mm: fix off-by-one bug in print_nodes_state() /sys/devices/system/node/{online,possible} outputs a garbage byte because print_nodes_state() returns content size + 1. To fix the bug, the patch changes the use of cpuset_sprintf_cpulist to follow the use at other places, which is clearer and safer. This bug was introduced since v2.6.24 (bde631a51876f23e9). Signed-off-by: Ryota Ozaki Cc: Lee Schermerhorn Signed-off-by: Andrew Morton --- drivers/base/node.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 90aa2a11a933..af1a177216f1 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf) { int n; - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]); - if (n > 0 && PAGE_SIZE > n + 1) { - *(buf + n++) = '\n'; - *(buf + n++) = '\0'; - } + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]); + buf[n++] = '\n'; + buf[n] = '\0'; return n; } -- 2.39.5