libc/blkoutstream: Zero the cache to avoid random data

and skip zero cache in lib_mtdoutstream_open since it's aleady done ih mtdoutstream_puts

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2024-08-19 01:19:29 +08:00
committed by archer
parent 00529f1626
commit fa57289d68
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -104,6 +104,11 @@ static int blkoutstream_puts(FAR struct lib_outstream_s *self,
}
else if (remain < sectorsize)
{
/* Set content to all 0 before caching,
* so no random content will be flushed
*/
memset(stream->cache, 0, sectorsize);
memcpy(stream->cache, ptr, remain);
self->nput += remain;
remain = 0;
+1 -1
View File
@@ -295,7 +295,7 @@ int lib_mtdoutstream_open(FAR struct lib_mtdoutstream_s *stream,
if (node->u.i_mtd->write == NULL)
#endif
{
stream->cache = lib_zalloc(stream->geo.erasesize);
stream->cache = lib_malloc(stream->geo.erasesize);
if (stream->cache == NULL)
{
close_mtddriver(node);