|
|
cfe731 |
From 2b9cf6fe72592379e4be1f2129c8031f0c2b5273 Mon Sep 17 00:00:00 2001
|
|
|
cfe731 |
From: Honggang Li <honli@redhat.com>
|
|
|
cfe731 |
Date: Fri, 12 Oct 2018 19:54:56 +0800
|
|
|
cfe731 |
Subject: [PATCH] Use precision specifier for scanf
|
|
|
cfe731 |
|
|
|
cfe731 |
If user input a string larger than the length of buffer, the stack memory
|
|
|
cfe731 |
will be corrupted.
|
|
|
cfe731 |
|
|
|
cfe731 |
Signed-off-by: Honggang Li <honli@redhat.com>
|
|
|
cfe731 |
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
|
|
|
cfe731 |
---
|
|
|
cfe731 |
opensm/main.c | 2 +-
|
|
|
cfe731 |
osmtest/osmtest.c | 2 +-
|
|
|
cfe731 |
2 files changed, 2 insertions(+), 2 deletions(-)
|
|
|
cfe731 |
|
|
|
cfe731 |
diff --git a/opensm/main.c b/opensm/main.c
|
|
|
cfe731 |
index 2d23fe2befef..8def799cea0f 100644
|
|
|
cfe731 |
--- a/opensm/main.c
|
|
|
cfe731 |
+++ b/opensm/main.c
|
|
|
cfe731 |
@@ -499,7 +499,7 @@ static ib_net64_t get_port_guid(IN osm_opensm_t * p_osm, uint64_t port_guid)
|
|
|
cfe731 |
fflush(stdout);
|
|
|
cfe731 |
if (scanf("%u", &choice) <= 0) {
|
|
|
cfe731 |
char junk[128];
|
|
|
cfe731 |
- if (scanf("%s", junk) <= 0)
|
|
|
cfe731 |
+ if (scanf("%127s", junk) <= 0)
|
|
|
cfe731 |
printf("\nError: Cannot scan!\n");
|
|
|
cfe731 |
} else if (choice == 0)
|
|
|
cfe731 |
return 0;
|
|
|
cfe731 |
diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c
|
|
|
cfe731 |
index 281b247a2e69..fa2e0704b8cc 100644
|
|
|
cfe731 |
--- a/osmtest/osmtest.c
|
|
|
cfe731 |
+++ b/osmtest/osmtest.c
|
|
|
cfe731 |
@@ -7352,7 +7352,7 @@ osmtest_get_user_port(IN osmtest_t * const p_osmt,
|
|
|
cfe731 |
fflush(stdout);
|
|
|
cfe731 |
if (scanf("%u", &choice) <= 0) {
|
|
|
cfe731 |
char junk[256];
|
|
|
cfe731 |
- if (scanf("%s", junk) <= 0)
|
|
|
cfe731 |
+ if (scanf("%255s", junk) <= 0)
|
|
|
cfe731 |
printf("\nError: Cannot scan!\n");
|
|
|
cfe731 |
} else if (choice && choice <= num_ports)
|
|
|
cfe731 |
break;
|
|
|
cfe731 |
--
|
|
|
cfe731 |
2.15.0-rc1
|
|
|
cfe731 |
|