mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -529,8 +529,7 @@ int smartfs_finddirentry(struct smartfs_mountpt_s *fs,
|
||||
goto errout;
|
||||
}
|
||||
|
||||
strncpy(fs->fs_workbuffer, segment, seglen);
|
||||
fs->fs_workbuffer[seglen] = '\0';
|
||||
strlcpy(fs->fs_workbuffer, segment, seglen + 1);
|
||||
|
||||
/* Search for "." and ".." as segment names */
|
||||
|
||||
@@ -669,10 +668,8 @@ int smartfs_finddirentry(struct smartfs_mountpt_s *fs,
|
||||
kmm_malloc(fs->fs_llformat.namesize + 1);
|
||||
}
|
||||
|
||||
memset(direntry->name, 0,
|
||||
fs->fs_llformat.namesize + 1);
|
||||
strncpy(direntry->name, entry->name,
|
||||
fs->fs_llformat.namesize);
|
||||
strlcpy(direntry->name, entry->name,
|
||||
fs->fs_llformat.namesize + 1);
|
||||
direntry->datlen = 0;
|
||||
|
||||
/* Scan the file's sectors to calculate the length
|
||||
@@ -1056,7 +1053,7 @@ int smartfs_createentry(FAR struct smartfs_mountpt_s *fs,
|
||||
entry->utc = time(NULL);
|
||||
#endif
|
||||
memset(entry->name, 0, fs->fs_llformat.namesize);
|
||||
strncpy(entry->name, filename, fs->fs_llformat.namesize);
|
||||
strlcpy(entry->name, filename, fs->fs_llformat.namesize);
|
||||
|
||||
/* Now write the new entry to the parent directory sector */
|
||||
|
||||
@@ -1102,7 +1099,7 @@ int smartfs_createentry(FAR struct smartfs_mountpt_s *fs,
|
||||
}
|
||||
|
||||
memset(direntry->name, 0, fs->fs_llformat.namesize + 1);
|
||||
strncpy(direntry->name, filename, fs->fs_llformat.namesize);
|
||||
strlcpy(direntry->name, filename, fs->fs_llformat.namesize);
|
||||
|
||||
ret = OK;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user