From 3f4846add00b3b6b901057165ef777f27b6aa562 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 26 May 2007 21:14:50 +0300 Subject: [PATCH] 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. --- src/terminal/screen.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/terminal/screen.c b/src/terminal/screen.c index b429ab46..c0cc29de 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -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);