diff options
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r-- | firmware/common/dircache.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 01ed72adc1..e846d55452 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c | |||
@@ -232,11 +232,11 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td) | |||
232 | return -2; | 232 | return -2; |
233 | 233 | ||
234 | td->pathpos = strlen(dircache_cur_path); | 234 | td->pathpos = strlen(dircache_cur_path); |
235 | strncpy(&dircache_cur_path[td->pathpos], "/", | 235 | strlcpy(&dircache_cur_path[td->pathpos], "/", |
236 | sizeof(dircache_cur_path) - td->pathpos - 1); | 236 | sizeof(dircache_cur_path) - td->pathpos); |
237 | #ifdef SIMULATOR | 237 | #ifdef SIMULATOR |
238 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, | 238 | strlcpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, |
239 | sizeof(dircache_cur_path) - td->pathpos - 2); | 239 | sizeof(dircache_cur_path) - td->pathpos - 1); |
240 | 240 | ||
241 | td->newdir = opendir_uncached(dircache_cur_path); | 241 | td->newdir = opendir_uncached(dircache_cur_path); |
242 | if (td->newdir == NULL) | 242 | if (td->newdir == NULL) |
@@ -245,8 +245,8 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td) | |||
245 | return -3; | 245 | return -3; |
246 | } | 246 | } |
247 | #else | 247 | #else |
248 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name, | 248 | strlcpy(&dircache_cur_path[td->pathpos+1], td->entry.name, |
249 | sizeof(dircache_cur_path) - td->pathpos - 2); | 249 | sizeof(dircache_cur_path) - td->pathpos - 1); |
250 | 250 | ||
251 | td->newdir = *td->dir; | 251 | td->newdir = *td->dir; |
252 | if (fat_opendir(IF_MV2(volume,) &td->newdir, | 252 | if (fat_opendir(IF_MV2(volume,) &td->newdir, |
@@ -399,7 +399,7 @@ static struct dircache_entry* dircache_get_entry(const char *path, | |||
399 | char* part; | 399 | char* part; |
400 | char* end; | 400 | char* end; |
401 | 401 | ||
402 | strncpy(namecopy, path, sizeof(namecopy) - 1); | 402 | strlcpy(namecopy, path, sizeof(namecopy)); |
403 | cache_entry = dircache_root; | 403 | cache_entry = dircache_root; |
404 | before = NULL; | 404 | before = NULL; |
405 | 405 | ||
@@ -926,7 +926,7 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute | |||
926 | char *new; | 926 | char *new; |
927 | long last_cache_size = dircache_size; | 927 | long last_cache_size = dircache_size; |
928 | 928 | ||
929 | strncpy(basedir, path, sizeof(basedir)-1); | 929 | strlcpy(basedir, path, sizeof(basedir)); |
930 | new = strrchr(basedir, '/'); | 930 | new = strrchr(basedir, '/'); |
931 | if (new == NULL) | 931 | if (new == NULL) |
932 | { | 932 | { |
@@ -997,8 +997,8 @@ void dircache_bind(int fd, const char *path) | |||
997 | { | 997 | { |
998 | if (fdbind_idx >= MAX_PENDING_BINDINGS) | 998 | if (fdbind_idx >= MAX_PENDING_BINDINGS) |
999 | return ; | 999 | return ; |
1000 | strncpy(fdbind_cache[fdbind_idx].path, path, | 1000 | strlcpy(fdbind_cache[fdbind_idx].path, path, |
1001 | sizeof(fdbind_cache[fdbind_idx].path)-1); | 1001 | sizeof(fdbind_cache[fdbind_idx].path)); |
1002 | fdbind_cache[fdbind_idx].fd = fd; | 1002 | fdbind_cache[fdbind_idx].fd = fd; |
1003 | fdbind_idx++; | 1003 | fdbind_idx++; |
1004 | return ; | 1004 | return ; |
@@ -1141,7 +1141,7 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1141 | /* Generate the absolute path for destination if necessary. */ | 1141 | /* Generate the absolute path for destination if necessary. */ |
1142 | if (newpath[0] != '/') | 1142 | if (newpath[0] != '/') |
1143 | { | 1143 | { |
1144 | strncpy(absolute_path, oldpath, sizeof(absolute_path)-1); | 1144 | strlcpy(absolute_path, oldpath, sizeof(absolute_path)); |
1145 | p = strrchr(absolute_path, '/'); | 1145 | p = strrchr(absolute_path, '/'); |
1146 | if (!p) | 1146 | if (!p) |
1147 | { | 1147 | { |
@@ -1151,7 +1151,7 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | *p = '\0'; | 1153 | *p = '\0'; |
1154 | strncpy(p, absolute_path, sizeof(absolute_path)-1-strlen(p)); | 1154 | strlcpy(p, absolute_path, sizeof(absolute_path)-strlen(p)); |
1155 | newpath = absolute_path; | 1155 | newpath = absolute_path; |
1156 | } | 1156 | } |
1157 | 1157 | ||
@@ -1246,7 +1246,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir) | |||
1246 | if (regentry == NULL) | 1246 | if (regentry == NULL) |
1247 | return NULL; | 1247 | return NULL; |
1248 | 1248 | ||
1249 | strncpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH-1); | 1249 | strlcpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH); |
1250 | dir->secondary_entry.size = regentry->size; | 1250 | dir->secondary_entry.size = regentry->size; |
1251 | dir->secondary_entry.startcluster = regentry->startcluster; | 1251 | dir->secondary_entry.startcluster = regentry->startcluster; |
1252 | dir->secondary_entry.attribute = regentry->attribute; | 1252 | dir->secondary_entry.attribute = regentry->attribute; |
@@ -1268,7 +1268,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir) | |||
1268 | 1268 | ||
1269 | dir->entry = ce->next; | 1269 | dir->entry = ce->next; |
1270 | 1270 | ||
1271 | strncpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH-1); | 1271 | strlcpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH); |
1272 | /* Can't do `dir->secondary_entry = *ce` | 1272 | /* Can't do `dir->secondary_entry = *ce` |
1273 | because that modifies the d_name pointer. */ | 1273 | because that modifies the d_name pointer. */ |
1274 | dir->secondary_entry.size = ce->size; | 1274 | dir->secondary_entry.size = ce->size; |