Skip to content

Commit

Permalink
fs/ntfs3: Add NULL ptr dereference checking at the end of attr_alloca…
Browse files Browse the repository at this point in the history
…te_frame()

[ Upstream commit aaab47f ]

It is preferable to exit through the out: label because
internal debugging functions are located there.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
aalexandrovich authored and gregkh committed Mar 1, 2024
1 parent 323b0ab commit 947c3f3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions fs/ntfs3/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,8 +1743,10 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
le_b = NULL;
attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
0, NULL, &mi_b);
if (!attr_b)
return -ENOENT;
if (!attr_b) {
err = -ENOENT;
goto out;
}

attr = attr_b;
le = le_b;
Expand Down Expand Up @@ -1825,13 +1827,15 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
ok:
run_truncate_around(run, vcn);
out:
if (new_valid > data_size)
new_valid = data_size;
if (attr_b) {
if (new_valid > data_size)
new_valid = data_size;

valid_size = le64_to_cpu(attr_b->nres.valid_size);
if (new_valid != valid_size) {
attr_b->nres.valid_size = cpu_to_le64(valid_size);
mi_b->dirty = true;
valid_size = le64_to_cpu(attr_b->nres.valid_size);
if (new_valid != valid_size) {
attr_b->nres.valid_size = cpu_to_le64(valid_size);
mi_b->dirty = true;
}
}

return err;
Expand Down

0 comments on commit 947c3f3

Please sign in to comment.