strncpy bugfix bugfix; UPDATE RECOMMENDED

This commit is contained in:
reenoo
2001-12-26 16:25:41 +00:00
parent 531ad030ea
commit c0c5bd28df
3 changed files with 20 additions and 12 deletions
+13 -5
View File
@@ -74,9 +74,9 @@ CFontz_init (lcd_logical_driver * driver, char *args)
int reboot = 0;
int contrast = DEFAULT_CONTRAST;
char device[256] = DEFAULT_DEVICE;
char device[200] = DEFAULT_DEVICE;
int speed = DEFAULT_SPEED;
char size[256] = DEFAULT_SIZE;
char size[200] = DEFAULT_SIZE;
CFontz = driver;
@@ -89,12 +89,12 @@ 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),sizeof(config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE)));
strncpy(device, config_get_string ( DriverName , "Device" , 0 , DEFAULT_DEVICE),sizeof(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),sizeof(config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE)));
strncpy(size, config_get_string ( DriverName , "Size" , 0 , DEFAULT_SIZE),sizeof(size));
size[sizeof(size)-1]=0;
if( sscanf(size , "%dx%d", &w, &h ) != 2
|| (w <= 0) || (w > LCD_MAX_WIDTH)
@@ -128,7 +128,7 @@ CFontz_init (lcd_logical_driver * driver, char *args)
/*Which speed*/
tmp = config_get_int ( DriverName , "Speed" , 0 , DEFAULT_OFFBRIGHTNESS);
tmp = config_get_int ( DriverName , "Speed" , 0 , DEFAULT_SPEED);
if (tmp == 1200) speed = B1200;
else if (tmp == 2400) speed = B2400;
else if (tmp == 9600) speed = B9600;
@@ -726,6 +726,14 @@ CFontz_string (int x, int y, char string[])
y -= 1;
for (i = 0; string[i]; i++) {
// For V2 of the firmware to get the block to display right
if (newfirmware && string[i]==-1) {
string[i]=214;
}
// Check for buffer overflows...
if ((y * CFontz->wid) + x + i > (CFontz->wid * CFontz->hgt))
break;
+5 -5
View File
@@ -247,17 +247,17 @@ 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),sizeof(config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR)));
strncpy(buf, config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR),sizeof(buf));
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),sizeof(config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR)));
strncpy(buf, config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR),sizeof(buf));
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), sizeof(config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT)));
strncpy(buf, config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT), sizeof(buf));
buf[sizeof(buf)-1]=0;
backlight_color = set_background_color(buf);
debug( RPT_DEBUG, "CURSES: using backlight color: %s", buf);
@@ -266,13 +266,13 @@ 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), sizeof(config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE)));
strncpy(buf, config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE), sizeof(buf));
buf[sizeof(buf)-1]=0;
int wid, hgt;
if( sscanf(buf , "%dx%d", &wid, &hgt ) != 2
|| (wid <= 0)
|| (hgt <= 0)) {
report (RPT_WARNING, "CURSES: Cannot read size: %s. Using default value.\n", buf);
report (RPT_WARNING, "CURSES: Cannot read size: %s. Using default value %s.\n", buf, CONF_DEF_SIZE);
sscanf( CONF_DEF_SIZE , "%dx%d", &wid, &hgt );
}
driver->wid = wid;
+2 -2
View File
@@ -187,7 +187,7 @@ lcdm001_cursorblink (int on)
int
lcdm001_init (struct lcd_logical_driver *driver, char *args)
{
char device[256];
char device[200];
int speed=B38400;
struct termios portset;
@@ -225,7 +225,7 @@ 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"), sizeof(config_get_string ( DriverName , "Device" , 0 , "/dev/lcd")));
strncpy(device, config_get_string ( DriverName , "Device" , 0 , "/dev/lcd"), sizeof(device));
device[sizeof(device)-1]=0;
report (RPT_INFO,"LCDM001: Using device: %s", device);