1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -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:
Kalle Olavi Niemitalo 2007-05-26 21:14:50 +03:00 committed by Witold Filipczyk
parent 6d14d95386
commit 3f4846add0

View File

@ -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"); 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)) {
set_screen_driver_opt(driver, term_spec); set_screen_driver_opt(driver, term_spec);
break; break;
} }
@ -416,7 +415,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);