[PATCH 3.4 014/125] HID: core: Avoid uninitialized buffer access

From: lizf
Date: Wed Oct 12 2016 - 08:38:29 EST

From: Richard Purdie <richard.purdie@xxxxxxxxxxxxxxxxxxx>

3.4.113-rc1 review patch. If anyone has any objections, please let me know.


commit 79b568b9d0c7c5d81932f4486d50b38efdd6da6d upstream.

hid_connect adds various strings to the buffer but they're all
conditional. You can find circumstances where nothing would be written
to it but the kernel will still print the supposedly empty buffer with
printk. This leads to corruption on the console/in the logs.

Ensure buf is initialized to an empty string.

Signed-off-by: Richard Purdie <richard.purdie@xxxxxxxxxxxxxxxxxxx>
[dvhart: Initialize string to "" rather than assign buf[0] = NULL;]
Cc: Jiri Kosina <jikos@xxxxxxxxxx>
Cc: linux-input@xxxxxxxxxxxxxxx
Signed-off-by: Darren Hart <dvhart@xxxxxxxxxxxxxxx>
Signed-off-by: Jiri Kosina <jkosina@xxxxxxx>
Signed-off-by: Zefan Li <lizefan@xxxxxxxxxx>
drivers/hid/hid-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 75fa2e7..b8ad132 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1301,7 +1301,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
"Multi-Axis Controller"
const char *type, *bus;
- char buf[64];
+ char buf[64] = "";
unsigned int i;
int len;
int ret;