summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-08-11 19:39:19 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-08-11 19:41:17 +0200
commita441cb616db547d366a796d0370d5f351b73b289 (patch)
tree3f013602a45752e339b9aa27d8669db5685d54b2
parent2cfbdcc66886bd4852f9e84b46fbf6bdc7d8a13e (diff)
ext2fs: clear inline data
When truncating a node with inline data, it's safer to really frob the inline data, to make sure ext2fs does not wrongly interprete it as block numbers.
-rw-r--r--ext2fs/truncate.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c
index 6d35fd20..44aab3c7 100644
--- a/ext2fs/truncate.c
+++ b/ext2fs/truncate.c
@@ -296,6 +296,19 @@ diskfs_truncate (struct node *node, off_t length)
is true for fast symlinks, and also apparently for some device nodes
in linux. */
{
+ off_t froblen = node->dn_stat.st_size;
+ off_t frobmax = sizeof(diskfs_node_disknode (node)->info.i_data);
+
+ if (froblen > frobmax)
+ {
+ ext2_warning ("inline data was %lld, more than max %lld",
+ (long long) froblen, (long long) frobmax);
+ froblen = frobmax;
+ }
+ froblen -= length;
+ memset (((char *) (diskfs_node_disknode (node)->info.i_data)) + length,
+ 0, froblen);
+
node->dn_stat.st_size = length;
node->dn_set_mtime = 1;
node->dn_set_ctime = 1;