public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch: s390: appldata: using strncpy() instead of sprintf()
@ 2013-05-27  2:59 Chen Gang
  2013-05-27  8:34 ` Geert Uytterhoeven
  0 siblings, 1 reply; 16+ messages in thread
From: Chen Gang @ 2013-05-27  2:59 UTC (permalink / raw)
  To: Martin Schwidefsky, Heiko Carstens, jang; +Cc: linux390, linux-s390, Linux-Arch


'buf[2]' is 2 bytes length, and sprintf() will append '\0' at the end
of string "?\n", so original implementation is memory overflow.

Need use strncpy() instead of sprintf().


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

diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index bae0f40..566ea87 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -212,7 +212,8 @@ appldata_timer_handler(ctl_table *ctl, int write,
 		return 0;
 	}
 	if (!write) {
-		len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
+		len = strncpy(buf, appldata_timer_active ? "1\n" : "0\n",
+								sizeof(buf));
 		if (len > *lenp)
 			len = *lenp;
 		if (copy_to_user(buffer, buf, len))
@@ -317,7 +318,7 @@ appldata_generic_handler(ctl_table *ctl, int write,
 		return 0;
 	}
 	if (!write) {
-		len = sprintf(buf, ops->active ? "1\n" : "0\n");
+		len = strncpy(buf, ops->active ? "1\n" : "0\n", sizeof(buf));
 		if (len > *lenp)
 			len = *lenp;
 		if (copy_to_user(buffer, buf, len)) {
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-05-29  7:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-27  2:59 [PATCH] arch: s390: appldata: using strncpy() instead of sprintf() Chen Gang
2013-05-27  8:34 ` Geert Uytterhoeven
2013-05-27  9:06   ` Chen Gang
2013-05-27  9:43     ` [PATCH] arch: s390: include: asm: typo issue for the redundency comma, found by cross compiling Chen Gang
2013-05-27  9:55   ` [PATCH v2] arch: s390: appldata: using strncpy() and strnlen() instead of sprintf() Chen Gang
2013-05-27 16:23     ` Gerald Schaefer
2013-05-28  4:58       ` Chen Gang
2013-05-28 10:22     ` David Howells
2013-05-28 11:03       ` Chen Gang
2013-05-28 12:17         ` David Howells
2013-05-28 16:03           ` Gerald Schaefer
2013-05-29  1:40             ` Chen Gang
2013-05-29  1:28           ` Chen Gang
2013-05-29  6:30             ` Dan Carpenter
2013-05-29  7:29               ` Chen Gang
2013-05-29  7:47                 ` Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox