[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 4/5] block: Fix potential Null pointer derefe
From: |
Max Reitz |
Subject: |
Re: [Qemu-devel] [PATCH v5 4/5] block: Fix potential Null pointer dereferences in vvfat.c |
Date: |
Sun, 11 Nov 2018 20:22:14 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 |
On 05.11.18 22:38, Liam Merwick wrote:
> The calls to find_mapping_for_cluster() may return NULL but it
> isn't always checked for before dereferencing the value returned.
> Additionally, add some asserts to cover cases where NULL can't
> be returned but which might not be obvious at first glance.
>
> Signed-off-by: Liam Merwick <address@hidden>
> ---
> block/vvfat.c | 50 ++++++++++++++++++++++++++++++++++----------------
> 1 file changed, 34 insertions(+), 16 deletions(-)
>
> diff --git a/block/vvfat.c b/block/vvfat.c
> index fc41841a5c3c..263274d9739a 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
[...]
> @@ -2428,16 +2424,13 @@ static int commit_direntries(BDRVVVFATState* s,
> direntry_t* direntry = array_get(&(s->directory), dir_index);
> uint32_t first_cluster = dir_index == 0 ? 0 :
> begin_of_direntry(direntry);
> mapping_t* mapping = find_mapping_for_cluster(s, first_cluster);
> -
> int factor = 0x10 * s->sectors_per_cluster;
> int old_cluster_count, new_cluster_count;
> - int current_dir_index = mapping->info.dir.first_dir_index;
> - int first_dir_index = current_dir_index;
> + int current_dir_index;
> + int first_dir_index;
> int ret, i;
> uint32_t c;
>
> -DLOG(fprintf(stderr, "commit_direntries for %s, parent_mapping_index %d\n",
> mapping->path, parent_mapping_index));
> -
> assert(direntry);
> assert(mapping);
Oh, having moved the condition below the declarations brings an
interesting point to light, which is that there is an assertion for it
here already. So...
> assert(mapping->begin == first_cluster);
> @@ -2445,6 +2438,15 @@ DLOG(fprintf(stderr, "commit_direntries for %s,
> parent_mapping_index %d\n", mapp
> assert(mapping->mode & MODE_DIRECTORY);
> assert(dir_index == 0 || is_directory(direntry));
>
> + if (mapping == NULL) {
> + return -1;
> + }
> +
...this should just not be added altogether.
> +DLOG(fprintf(stderr, "commit_direntries for %s, parent_mapping_index %d\n",
> + mapping->path, parent_mapping_index));
Moving this and the following dereferencing statements below that
assertion is reasonable, though. I think you should indent the DLOG()
while you're at it, though, because there is no reason not to, and the
way it is here just violates the coding style. (Disregarding that
vvfat.c effectively is a complete violation of the qemu coding style.
*cough*)
> +
> + current_dir_index = mapping->info.dir.first_dir_index;
> + first_dir_index = current_dir_index;
> mapping->info.dir.parent_mapping_index = parent_mapping_index;
>
> if (first_cluster == 0) {
So with the "if (mapping == NULL) {}" block above (hunk @@2445) dropped
and the DLOG() indented:
Reviewed-by: Max Reitz <address@hidden>
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v5 0/5] off-by-one and NULL pointer accesses detected by static analysis, Liam Merwick, 2018/11/05
- [Qemu-devel] [PATCH v5 5/5] qcow2: Read outside array bounds in qcow2_pre_write_overlap_check(), Liam Merwick, 2018/11/05
- [Qemu-devel] [PATCH v5 1/5] job: Fix off-by-one assert checks for JobSTT and JobVerbTable, Liam Merwick, 2018/11/05
- [Qemu-devel] [PATCH v5 3/5] qemu-img: assert block_job_get() does not return NULL in img_commit(), Liam Merwick, 2018/11/05
- [Qemu-devel] [PATCH v5 4/5] block: Fix potential Null pointer dereferences in vvfat.c, Liam Merwick, 2018/11/05
- Re: [Qemu-devel] [PATCH v5 4/5] block: Fix potential Null pointer dereferences in vvfat.c,
Max Reitz <=
- [Qemu-devel] [PATCH v5 2/5] block: Null pointer dereference in blk_root_get_parent_desc(), Liam Merwick, 2018/11/05
- Re: [Qemu-devel] [PATCH v5 0/5] off-by-one and NULL pointer accesses detected by static analysis, Max Reitz, 2018/11/11