Replace all strncpy with strlcpy for safety

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2022-08-24 02:23:20 +00:00
committed by Xiang Xiao
parent 96f77cb6a6
commit e4e3208180
45 changed files with 89 additions and 107 deletions
+5 -8
View File
@@ -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;