mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Compare screen_driver.name with strcmp, not memcmp.
screen_driver_change_hook was comparing only strlen(name) characters and ignoring the '\0'. To reproduce the bug in ELinks 0.11.3 and ELinks 0.12.GIT: - Run TERM=screen elinks. - In another terminal, run TERM=scr elinks. Quit this slave ELinks. - Open the terminal options dialog and set 16 colors. - Open the option manager and change the terminal.scr.colors option to 1 and back to 0. - Note that ELinks no longer displays colors. That bug could be fixed just by using len+1 instead of len. However, there is also another bug: memcmp may compare the specified number of bytes, even if some of the earlier ones differ; thus, it could in principle read past the end of the malloc block and thereby crash ELinks. Using strcmp may be a little slower but I do not believe it could become a bottleneck.
This commit is contained in:
parent
6d14d95386
commit
3f4846add0
@ -370,10 +370,9 @@ screen_driver_change_hook(struct session *ses, struct option *term_spec,
|
||||
enum term_mode_type type = get_opt_int_tree(term_spec, "type");
|
||||
struct screen_driver *driver;
|
||||
unsigned char *name = term_spec->name;
|
||||
int len = strlen(name);
|
||||
|
||||
foreach (driver, active_screen_drivers)
|
||||
if (driver->type == type && !memcmp(driver->name, name, len)) {
|
||||
if (driver->type == type && !strcmp(driver->name, name)) {
|
||||
set_screen_driver_opt(driver, term_spec);
|
||||
break;
|
||||
}
|
||||
@ -416,7 +415,7 @@ get_screen_driver(struct terminal *term)
|
||||
|
||||
foreach (driver, active_screen_drivers) {
|
||||
if (driver->type != type) continue;
|
||||
if (memcmp(driver->name, name, len + 1)) continue;
|
||||
if (strcmp(driver->name, name)) continue;
|
||||
|
||||
/* Some simple probably useless MRU ;) */
|
||||
move_to_top_of_list(active_screen_drivers, driver);
|
||||
|
Loading…
x
Reference in New Issue
Block a user