Skip to content

Commit af9274e

Browse files
gkodinovzmur
authored andcommitted
Bug#36615714: buffer overrun in my_print_help
Backport to 5.7.49. Breaking the comment for a mysys option definition requires that no single word at the end of the comment (or every 57 chars if the comment is longer than 57 chars * 2) is longer 57 chars. Fixed the logic to handle the lack of space. Change-Id: I2f48da5e0d066c208606058d095c7706dc12722c
1 parent 74f90ab commit af9274e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

mysys_ssl/my_getopt.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2002, 2023, Oracle and/or its affiliates.
1+
/* Copyright (c) 2002, 2024, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -1489,11 +1489,24 @@ void my_print_help(const struct my_option *options)
14891489

14901490
while ((uint) (end - comment) > comment_space)
14911491
{
1492-
for (line_end= comment + comment_space; *line_end != ' '; line_end--)
1492+
bool had_space;
1493+
// find the last space before the limit to break the comment on
1494+
for (line_end= comment + comment_space;
1495+
line_end > comment && *line_end != ' ';
1496+
line_end--)
14931497
{}
1498+
// if no space is found break at the limit - 1 (for the new line)
1499+
if (line_end == comment && *comment != ' ')
1500+
{
1501+
line_end = comment + comment_space - 1;
1502+
had_space = false;
1503+
}
1504+
else
1505+
had_space = true;
14941506
for (; comment != line_end; comment++)
14951507
putchar(*comment);
1496-
comment++; /* skip the space, as a newline will take it's place now */
1508+
if (had_space)
1509+
comment++; /* skip the space, as a newline will take it's place now */
14971510
putchar('\n');
14981511
for (col= 0; col < name_space; col++)
14991512
putchar(' ');

0 commit comments

Comments
 (0)