diff options
author | Arnd Bergmann <arnd@arndb.de> | 2016-11-29 06:51:04 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-11-29 14:20:07 -0500 |
commit | 5020ded78348092eac5e9909018f6d53e24eadb6 (patch) | |
tree | 6c13f132c3788411b7a8efc2ea8e24f27dfbfa3c /drivers/tty | |
parent | f209fa03fc9d131b3108c2e4936181eabab87416 (diff) |
tty: nozomi: avoid sprintf buffer overflow
Testing with a gcc-7 snapshot produced an internal compiler error
for this file:
drivers/tty/nozomi.c: In function 'receive_flow_control':
drivers/tty/nozomi.c:919:12: internal compiler error: in get_substring_ranges_for_loc, at input.c:1388
static int receive_flow_control(struct nozomi *dc)
I've reported this at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78569
but also noticed that the code line contains a stack overflow, as it prints
a string into a slightly shorter fixed-length 'tmp' variable.
A lot of the code here is unnecessary and can be expressed in a simpler
way, relying on the fact that removing the 'DEBUG' macro will also get
rid of all pr_debug() calls. This change should not change any of the
output but avoids both the stack overflow and the gcc crash.
The stack overflow will not happen unless a module load parameter is
also set to enable the debug messages.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/nozomi.c | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index e2020a691058..39b3723a32a6 100644 --- a/drivers/tty/nozomi.c +++ b/drivers/tty/nozomi.c | |||
@@ -63,44 +63,23 @@ | |||
63 | 63 | ||
64 | #define VERSION_STRING DRIVER_DESC " 2.1d" | 64 | #define VERSION_STRING DRIVER_DESC " 2.1d" |
65 | 65 | ||
66 | /* Macros definitions */ | ||
67 | |||
68 | /* Default debug printout level */ | 66 | /* Default debug printout level */ |
69 | #define NOZOMI_DEBUG_LEVEL 0x00 | 67 | #define NOZOMI_DEBUG_LEVEL 0x00 |
70 | |||
71 | #define P_BUF_SIZE 128 | ||
72 | #define NFO(_err_flag_, args...) \ | ||
73 | do { \ | ||
74 | char tmp[P_BUF_SIZE]; \ | ||
75 | snprintf(tmp, sizeof(tmp), ##args); \ | ||
76 | printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \ | ||
77 | __func__, tmp); \ | ||
78 | } while (0) | ||
79 | |||
80 | #define DBG1(args...) D_(0x01, ##args) | ||
81 | #define DBG2(args...) D_(0x02, ##args) | ||
82 | #define DBG3(args...) D_(0x04, ##args) | ||
83 | #define DBG4(args...) D_(0x08, ##args) | ||
84 | #define DBG5(args...) D_(0x10, ##args) | ||
85 | #define DBG6(args...) D_(0x20, ##args) | ||
86 | #define DBG7(args...) D_(0x40, ##args) | ||
87 | #define DBG8(args...) D_(0x80, ##args) | ||
88 | |||
89 | #ifdef DEBUG | ||
90 | /* Do we need this settable at runtime? */ | ||
91 | static int debug = NOZOMI_DEBUG_LEVEL; | 68 | static int debug = NOZOMI_DEBUG_LEVEL; |
69 | module_param(debug, int, S_IRUGO | S_IWUSR); | ||
92 | 70 | ||
93 | #define D(lvl, args...) do \ | 71 | /* Macros definitions */ |
94 | {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \ | 72 | #define DBG_(lvl, fmt, args...) \ |
95 | while (0) | 73 | do { \ |
96 | #define D_(lvl, args...) D(lvl, ##args) | 74 | if (lvl & debug) \ |
97 | 75 | pr_debug("[%d] %s(): " fmt "\n", \ | |
98 | /* These printouts are always printed */ | 76 | __LINE__, __func__, ##args); \ |
77 | } while (0) | ||
99 | 78 | ||
100 | #else | 79 | #define DBG1(args...) DBG_(0x01, ##args) |
101 | static int debug; | 80 | #define DBG2(args...) DBG_(0x02, ##args) |
102 | #define D_(lvl, args...) | 81 | #define DBG3(args...) DBG_(0x04, ##args) |
103 | #endif | 82 | #define DBG4(args...) DBG_(0x08, ##args) |
104 | 83 | ||
105 | /* TODO: rewrite to optimize macros... */ | 84 | /* TODO: rewrite to optimize macros... */ |
106 | 85 | ||
@@ -1943,7 +1922,5 @@ static __exit void nozomi_exit(void) | |||
1943 | module_init(nozomi_init); | 1922 | module_init(nozomi_init); |
1944 | module_exit(nozomi_exit); | 1923 | module_exit(nozomi_exit); |
1945 | 1924 | ||
1946 | module_param(debug, int, S_IRUGO | S_IWUSR); | ||
1947 | |||
1948 | MODULE_LICENSE("Dual BSD/GPL"); | 1925 | MODULE_LICENSE("Dual BSD/GPL"); |
1949 | MODULE_DESCRIPTION(DRIVER_DESC); | 1926 | MODULE_DESCRIPTION(DRIVER_DESC); |