mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -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.
[ Backported from commit f6f5eeceb7
in
ELinks 0.12.GIT. --KON ]
This commit is contained in:
parent
b641515fcc
commit
38497c4b37
@ -252,10 +252,9 @@ screen_driver_change_hook(struct session *ses, struct option *term_spec,
|
|||||||
enum term_mode_type type = get_opt_int_tree(term_spec, "type");
|
enum term_mode_type type = get_opt_int_tree(term_spec, "type");
|
||||||
struct screen_driver *driver;
|
struct screen_driver *driver;
|
||||||
unsigned char *name = term_spec->name;
|
unsigned char *name = term_spec->name;
|
||||||
int len = strlen(name);
|
|
||||||
|
|
||||||
foreach (driver, active_screen_drivers)
|
foreach (driver, active_screen_drivers)
|
||||||
if (driver->type == type && !memcmp(driver->name, name, len)) {
|
if (driver->type == type && !strcmp(driver->name, name)) {
|
||||||
update_screen_driver(driver, term_spec);
|
update_screen_driver(driver, term_spec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -294,7 +293,7 @@ get_screen_driver(struct terminal *term)
|
|||||||
|
|
||||||
foreach (driver, active_screen_drivers) {
|
foreach (driver, active_screen_drivers) {
|
||||||
if (driver->type != type) continue;
|
if (driver->type != type) continue;
|
||||||
if (memcmp(driver->name, name, len + 1)) continue;
|
if (strcmp(driver->name, name)) continue;
|
||||||
|
|
||||||
/* Some simple probably useless MRU ;) */
|
/* Some simple probably useless MRU ;) */
|
||||||
move_to_top_of_list(active_screen_drivers, driver);
|
move_to_top_of_list(active_screen_drivers, driver);
|
||||||
|
Loading…
Reference in New Issue
Block a user