strncpy bugfix; UPDATE RECOMMENDED

This commit is contained in:
reenoo
2001-12-25 21:16:15 +00:00
parent 09b4ff9271
commit 531ad030ea
3 changed files with 38 additions and 25 deletions
+4 -4
View File
@@ -89,13 +89,13 @@ CFontz_init (lcd_logical_driver * driver, char *args)
/*Read config file*/
/*Which serial device should be used*/
strncpy(device, config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE),200);
if (strlen(device)>199) strncat(device, "\0", 1);
strncpy(device, config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE),sizeof(config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE)));
device[sizeof(device)-1]=0;
debug (RPT_INFO,"CFontz: Using device: %s", device);
/*Which size*/
strncpy(size, config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE),200);
if (strlen(size)>199) strncat(size, "\0", 1);
strncpy(size, config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE),sizeof(config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE)));
size[sizeof(size)-1]=0;
if( sscanf(size , "%dx%d", &w, &h ) != 2
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) {
+8 -8
View File
@@ -247,18 +247,18 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
/*Get color settings*/
/*foreground color*/
strncpy(buf, config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR),200);
if (strlen(buf)>199) strncat(buf, "\0", 1);
strncpy(buf, config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR),sizeof(config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR)));
buf[sizeof(buf)-1]=0;
fore_color = set_foreground_color(buf);
debug( RPT_DEBUG, "CURSES: using foreground color: %s", buf);
/*background color*/
strncpy(buf, config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR),200);
if (strlen(buf)>199) strncat(buf, "\0", 1);
strncpy(buf, config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR),sizeof(config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR)));
buf[sizeof(buf)-1]=0;
back_color = set_background_color(buf);
debug( RPT_DEBUG, "CURSES: using background color: %s", buf);
/*backlight color*/
strncpy(buf, config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT),200);
if (strlen(buf)>199) strncat(buf, "\0", 1);
strncpy(buf, config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT), sizeof(config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT)));
buf[sizeof(buf)-1]=0;
backlight_color = set_background_color(buf);
debug( RPT_DEBUG, "CURSES: using backlight color: %s", buf);
@@ -266,8 +266,8 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
// Or maybe don't do so? - Rene Wagner
/*Get size settings*/
strncpy(buf, config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE),200);
if (strlen(buf)>199) strncat(buf, "\0", 1);
strncpy(buf, config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE), sizeof(config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE)));
buf[sizeof(buf)-1]=0;
int wid, hgt;
if( sscanf(buf , "%dx%d", &wid, &hgt ) != 2
|| (wid <= 0)
+26 -13
View File
@@ -131,23 +131,35 @@ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
static void lcdm001_cursorblink (int on);
static void lcdm001_string (int x, int y, char *string);
static char parse_lcdm001_keypad_setting ( char *s);
static char lcdm001_parse_keypad_setting ( char * sectionname, char * keyname, char * default_value );
#define ValidX(x) if ((x) > lcdm001->wid) { (x) = lcdm001->wid; } else (x) = (x) < 1 ? 1 : (x);
#define ValidY(y) if ((y) > lcdm001->hgt) { (y) = lcdm001->hgt; } else (y) = (y) < 1 ? 1 : (y);
// Parse one key from the configfile
static char parse_lcdm001_keypad_setting (char * s)
static char lcdm001_parse_keypad_setting (char * sectionname, char * keyname, char * default_value)
{
char return_val=0;
if (strcmp(s, "LeftKey")==0){
char return_val = 0;
if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "LeftKey")==0) {
return_val=LEFT_KEY;
} else if (strcmp(s, "RightKey")==0){
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "RightKey")==0) {
return_val=RIGHT_KEY;
} else if (strcmp(s, "UpKey")==0){
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "UpKey")==0) {
return_val=UP_KEY;
} else if (strcmp(s, "DownKey")==0) {
} else if (strcmp( config_get_string ( sectionname, keyname, 0, default_value), "DownKey")==0) {
return_val=DOWN_KEY;
} else {
report (RPT_WARNING, "LCDM001: Invalid config file setting for %s. Using default value %s.\n", keyname, default_value);
if (strcmp (default_value, "LeftKey")==0) {
return_val=LEFT_KEY;
} else if (strcmp (default_value, "RightKey")==0) {
return_val=RIGHT_KEY;
} else if (strcmp (default_value, "UpKey")==0) {
return_val=UP_KEY;
} else if (strcmp (default_value, "DownKey")==0) {
return_val=DOWN_KEY;
}
}
return return_val;
}
@@ -213,15 +225,16 @@ lcdm001_init (struct lcd_logical_driver *driver, char *args)
// READ CONFIG FILE:
// which serial device should be used
strncpy(device, config_get_string ( DriverName , "Device" , 0 , "/dev/lcd"),200);
if (strlen(device)>199) strncat(device, "\0", 1);
strncpy(device, config_get_string ( DriverName , "Device" , 0 , "/dev/lcd"), sizeof(config_get_string ( DriverName , "Device" , 0 , "/dev/lcd")));
device[sizeof(device)-1]=0;
report (RPT_INFO,"LCDM001: Using device: %s", device);
// keypad settings
pause_key = parse_lcdm001_keypad_setting (config_get_string ( DriverName, "PauseKey", 0, "DownKey"));
back_key = parse_lcdm001_keypad_setting (config_get_string ( DriverName, "BackKey", 0, "LeftKey"));
forward_key = parse_lcdm001_keypad_setting (config_get_string ( DriverName, "ForwardKey", 0, "RightKey"));
main_menu_key = parse_lcdm001_keypad_setting (config_get_string ( DriverName, "MainMenuKey", 0, "UpKey"));
pause_key = lcdm001_parse_keypad_setting (DriverName, "PauseKey", "DownKey");
back_key = lcdm001_parse_keypad_setting (DriverName, "BackKey", "LeftKey");
forward_key = lcdm001_parse_keypad_setting (DriverName, "ForwardKey", "RightKey");
main_menu_key = lcdm001_parse_keypad_setting (DriverName, "MainMenuKey", "UpKey");
// Set up io port correctly, and open it...
debug( RPT_DEBUG, "LCDM001: Opening serial device: %s", device);