diff options
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/apps/settings.c b/apps/settings.c index e2f40a1f44..29360f14d3 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -246,8 +246,7 @@ static bool cfg_string_to_int(int setting_id, int* out, const char* str) | |||
246 | } | 246 | } |
247 | else return false; | 247 | else return false; |
248 | } | 248 | } |
249 | strncpy(temp, start, end-start); | 249 | strlcpy(temp, start, end-start+1); |
250 | temp[end-start] = '\0'; | ||
251 | if (!strcmp(str, temp)) | 250 | if (!strcmp(str, temp)) |
252 | { | 251 | { |
253 | *out = count; | 252 | *out = count; |
@@ -331,20 +330,18 @@ bool settings_load_config(const char* file, bool apply) | |||
331 | settings[i].filename_setting->prefix, | 330 | settings[i].filename_setting->prefix, |
332 | len)) | 331 | len)) |
333 | { | 332 | { |
334 | strncpy(storage,&value[len],MAX_PATH); | 333 | strlcpy(storage, &value[len], MAX_PATH); |
335 | } | 334 | } |
336 | else strncpy(storage,value,MAX_PATH); | 335 | else strlcpy(storage, value, MAX_PATH); |
337 | } | 336 | } |
338 | else strncpy(storage,value,MAX_PATH); | 337 | else strlcpy(storage, value, MAX_PATH); |
339 | if (settings[i].filename_setting->suffix) | 338 | if (settings[i].filename_setting->suffix) |
340 | { | 339 | { |
341 | char *s = strcasestr(storage,settings[i].filename_setting->suffix); | 340 | char *s = strcasestr(storage,settings[i].filename_setting->suffix); |
342 | if (s) *s = '\0'; | 341 | if (s) *s = '\0'; |
343 | } | 342 | } |
344 | strncpy((char*)settings[i].setting,storage, | 343 | strlcpy((char*)settings[i].setting, storage, |
345 | settings[i].filename_setting->max_len); | 344 | settings[i].filename_setting->max_len); |
346 | ((char*)settings[i].setting) | ||
347 | [settings[i].filename_setting->max_len-1] = '\0'; | ||
348 | break; | 345 | break; |
349 | } | 346 | } |
350 | } | 347 | } |
@@ -379,12 +376,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) | |||
379 | if (value[count] == val) | 376 | if (value[count] == val) |
380 | { | 377 | { |
381 | if (end == NULL) | 378 | if (end == NULL) |
382 | strncpy(buf, start, buf_len); | 379 | strlcpy(buf, start, buf_len); |
383 | else | 380 | else |
384 | { | 381 | { |
385 | int len = (buf_len > (end-start))? end-start: buf_len; | 382 | int len = (buf_len > (end-start))? end-start: buf_len; |
386 | strncpy(buf, start, len); | 383 | strlcpy(buf, start, len+1); |
387 | buf[len] = '\0'; | ||
388 | } | 384 | } |
389 | return true; | 385 | return true; |
390 | } | 386 | } |
@@ -408,12 +404,11 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) | |||
408 | } | 404 | } |
409 | end = strchr(start,','); | 405 | end = strchr(start,','); |
410 | if (end == NULL) | 406 | if (end == NULL) |
411 | strncpy(buf, start, buf_len); | 407 | strlcpy(buf, start, buf_len); |
412 | else | 408 | else |
413 | { | 409 | { |
414 | int len = (buf_len > (end-start))? end-start: buf_len; | 410 | int len = (buf_len > (end-start))? end-start: buf_len; |
415 | strncpy(buf, start, len); | 411 | strlcpy(buf, start, len+1); |
416 | buf[len] = '\0'; | ||
417 | } | 412 | } |
418 | return true; | 413 | return true; |
419 | } | 414 | } |
@@ -468,7 +463,7 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) | |||
468 | (char*)settings[i].setting, | 463 | (char*)settings[i].setting, |
469 | settings[i].filename_setting->suffix); | 464 | settings[i].filename_setting->suffix); |
470 | } | 465 | } |
471 | else strncpy(buf,(char*)settings[i].setting, | 466 | else strlcpy(buf,(char*)settings[i].setting, |
472 | settings[i].filename_setting->max_len); | 467 | settings[i].filename_setting->max_len); |
473 | break; | 468 | break; |
474 | } /* switch () */ | 469 | } /* switch () */ |
@@ -1011,7 +1006,7 @@ void reset_setting(const struct settings_list *setting, void *var) | |||
1011 | break; | 1006 | break; |
1012 | case F_T_CHARPTR: | 1007 | case F_T_CHARPTR: |
1013 | case F_T_UCHARPTR: | 1008 | case F_T_UCHARPTR: |
1014 | strncpy((char*)var, setting->default_val.charptr, | 1009 | strlcpy((char*)var, setting->default_val.charptr, |
1015 | setting->filename_setting->max_len); | 1010 | setting->filename_setting->max_len); |
1016 | break; | 1011 | break; |
1017 | } | 1012 | } |
@@ -1114,7 +1109,7 @@ static void set_option_formatter(char* buf, size_t size, int item, const char* u | |||
1114 | { | 1109 | { |
1115 | (void)unit; | 1110 | (void)unit; |
1116 | const unsigned char *text = set_option_options[item].string; | 1111 | const unsigned char *text = set_option_options[item].string; |
1117 | strncpy(buf, P2STR(text), size); | 1112 | strlcpy(buf, P2STR(text), size); |
1118 | } | 1113 | } |
1119 | static int32_t set_option_get_talk_id(int value, int unit) | 1114 | static int32_t set_option_get_talk_id(int value, int unit) |
1120 | { | 1115 | { |
@@ -1173,12 +1168,11 @@ void set_file(const char* filename, char* setting, int maxlen) | |||
1173 | } | 1168 | } |
1174 | if(ptr == fptr) extlen = 0; | 1169 | if(ptr == fptr) extlen = 0; |
1175 | 1170 | ||
1176 | if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) || | 1171 | if (strncasecmp(ROCKBOX_DIR, filename, strlen(ROCKBOX_DIR)) || |
1177 | (len-extlen > maxlen)) | 1172 | (len-extlen > maxlen)) |
1178 | return; | 1173 | return; |
1179 | 1174 | ||
1180 | strncpy(setting, fptr, len-extlen); | 1175 | strlcpy(setting, fptr, len-extlen+1); |
1181 | setting[len-extlen]=0; | ||
1182 | 1176 | ||
1183 | settings_save(); | 1177 | settings_save(); |
1184 | } | 1178 | } |