Skip to content

Commit 43bcac9

Browse files
guohao15xiaoxiang781216
authored andcommitted
tmpfs: old data was loaded when SEEK_SET beyond end of the file
Signed-off-by: guohao15 <[email protected]>
1 parent 7f16770 commit 43bcac9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fs/tmpfs/fs_tmpfs.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,27 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s *tfo,
281281
* zero.
282282
*/
283283

284-
if (newsize > 0)
284+
if (newsize == 0)
285+
{
286+
/* Free the file object */
287+
288+
kmm_free(tfo->tfo_data);
289+
tfo->tfo_data = NULL;
290+
tfo->tfo_alloc = 0;
291+
tfo->tfo_size = 0;
292+
return OK;
293+
}
294+
else if (newsize > 0)
285295
{
286296
/* Otherwise, don't realloc unless the object has shrunk by a
287297
* lot.
288298
*/
289299

290300
delta = tfo->tfo_alloc - newsize;
301+
302+
/* We should make sure the shrunked memory be zero */
303+
304+
memset(tfo->tfo_data + newsize, 0, delta);
291305
if (delta <= CONFIG_FS_TMPFS_FILE_FREEGUARD)
292306
{
293307
/* Hasn't shrunk enough.. Return doing nothing for now */

0 commit comments

Comments
 (0)