* [PATCH 0/6] Btrfs progs, coverity fixes for 3.18
@ 2014-12-19 16:06 David Sterba
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
` (5 more replies)
0 siblings, 6 replies; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
A few straightforward fixes.
David Sterba (6):
btrfs-progs: corrupt block, add missing break to option I
btrfs-progs: corrupt block, add break after option U
btrfs-progs: fragments, close output file on error
btrfs-progs: check result of first_cache_extent
btrfs-progs: check allocation result in add_clone_source
btrfs-progs: let btrfs_free_path accept NULL
btrfs-corrupt-block.c | 2 ++
btrfs-fragments.c | 7 +++++--
cmds-check.c | 2 ++
cmds-send.c | 25 +++++++++++++++++++++----
ctree.c | 2 ++
5 files changed, 32 insertions(+), 6 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 2/6] btrfs-progs: corrupt block, add break after option U David Sterba
` (4 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Using -I would imply -d.
Resolves-Coverity-CID: 1258792
Signed-off-by: David Sterba <dsterba@suse.cz>
---
btrfs-corrupt-block.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index af9ae4d4047c..aeeb1b298f66 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -1096,6 +1096,7 @@ int main(int ac, char **av)
break;
case 'I':
corrupt_item = 1;
+ break;
case 'd':
delete = 1;
break;
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/6] btrfs-progs: corrupt block, add break after option U
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 3/6] btrfs-progs: fragments, close output file on error David Sterba
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Resolves-Coverity-CID: 1258793
Signed-off-by: David Sterba <dsterba@suse.cz>
---
btrfs-corrupt-block.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index aeeb1b298f66..b477e878376b 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -1068,6 +1068,7 @@ int main(int ac, char **av)
break;
case 'U':
chunk_tree = 1;
+ break;
case 'i':
inode = arg_strtou64(optarg);
break;
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/6] btrfs-progs: fragments, close output file on error
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
2014-12-19 16:06 ` [PATCH 2/6] btrfs-progs: corrupt block, add break after option U David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:50 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 4/6] btrfs-progs: check result of first_cache_extent David Sterba
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Resolves-Coverity-CID: 1258794
Signed-off-by: David Sterba <dsterba@suse.cz>
---
btrfs-fragments.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/btrfs-fragments.c b/btrfs-fragments.c
index d03c2c3e7319..360f10f87bfa 100644
--- a/btrfs-fragments.c
+++ b/btrfs-fragments.c
@@ -233,7 +233,7 @@ list_fragments(int fd, u64 flags, char *dir)
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
fprintf(stderr, "ERROR: can't perform the search\n");
- return ret;
+ goto out_close;
}
/* the ioctl returns the number of item it found in nr_items */
if (sk->nr_items == 0)
@@ -373,7 +373,10 @@ skip:;
fprintf(html, "</p>");
}
fprintf(html, "</body></html>\n");
-
+
+out_close:
+ fclose(html);
+
return ret;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/6] btrfs-progs: check result of first_cache_extent
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
` (2 preceding siblings ...)
2014-12-19 16:06 ` [PATCH 3/6] btrfs-progs: fragments, close output file on error David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:56 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source David Sterba
2014-12-19 16:06 ` [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL David Sterba
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
If the tree's empty, we'll get NULL and dereference it.
Resolves-Coverity-CID: 1248828
Signed-off-by: David Sterba <dsterba@suse.cz>
---
cmds-check.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/cmds-check.c b/cmds-check.c
index 6eea36c2f52c..3e7a4ebdce44 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -8075,6 +8075,8 @@ static void free_roots_info_cache(void)
struct root_item_info *rii;
entry = first_cache_extent(roots_info_cache);
+ if (!entry)
+ break;
remove_cache_extent(roots_info_cache, entry);
rii = container_of(entry, struct root_item_info, cache_extent);
free(rii);
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
` (3 preceding siblings ...)
2014-12-19 16:06 ` [PATCH 4/6] btrfs-progs: check result of first_cache_extent David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:58 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL David Sterba
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Resolves-Coverity-CID: 1054894
Signed-off-by: David Sterba <dsterba@suse.cz>
---
cmds-send.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/cmds-send.c b/cmds-send.c
index b17b5e2ca666..9b32c1f0e624 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -172,11 +172,16 @@ out:
return ret;
}
-static void add_clone_source(struct btrfs_send *s, u64 root_id)
+static int add_clone_source(struct btrfs_send *s, u64 root_id)
{
s->clone_sources = realloc(s->clone_sources,
sizeof(*s->clone_sources) * (s->clone_sources_count + 1));
+
+ if (!s->clone_sources)
+ return -ENOMEM;
s->clone_sources[s->clone_sources_count++] = root_id;
+
+ return 0;
}
static int write_buf(int fd, const void *buf, int size)
@@ -475,7 +480,11 @@ int cmd_send(int argc, char **argv)
goto out;
}
- add_clone_source(&send, root_id);
+ ret = add_clone_source(&send, root_id);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: not enough memory\n");
+ goto out;
+ }
subvol_uuid_search_finit(&send.sus);
free(subvol);
subvol = NULL;
@@ -575,7 +584,11 @@ int cmd_send(int argc, char **argv)
goto out;
}
- add_clone_source(&send, parent_root_id);
+ ret = add_clone_source(&send, parent_root_id);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: not enough memory\n");
+ goto out;
+ }
}
for (i = optind; i < argc; i++) {
@@ -671,7 +684,11 @@ int cmd_send(int argc, char **argv)
goto out;
/* done with this subvol, so add it to the clone sources */
- add_clone_source(&send, root_id);
+ ret = add_clone_source(&send, root_id);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: not enough memory\n");
+ goto out;
+ }
parent_root_id = 0;
full_send = 0;
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
` (4 preceding siblings ...)
2014-12-19 16:06 ` [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source David Sterba
@ 2014-12-19 16:06 ` David Sterba
2014-12-19 16:58 ` Eric Sandeen
5 siblings, 1 reply; 14+ messages in thread
From: David Sterba @ 2014-12-19 16:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Same in kernel and matches semantics of free().
Resolves-Coverity-CID: 1054881
Signed-off-by: David Sterba <dsterba@suse.cz>
---
ctree.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ctree.c b/ctree.c
index bd6cb125b2a2..589efa3db17e 100644
--- a/ctree.c
+++ b/ctree.c
@@ -48,6 +48,8 @@ struct btrfs_path *btrfs_alloc_path(void)
void btrfs_free_path(struct btrfs_path *p)
{
+ if (!p)
+ return;
btrfs_release_path(p);
kfree(p);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
@ 2014-12-19 16:49 ` Eric Sandeen
0 siblings, 0 replies; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:49 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> Using -I would imply -d.
>
> Resolves-Coverity-CID: 1258792
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> btrfs-corrupt-block.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
> index af9ae4d4047c..aeeb1b298f66 100644
> --- a/btrfs-corrupt-block.c
> +++ b/btrfs-corrupt-block.c
> @@ -1096,6 +1096,7 @@ int main(int ac, char **av)
> break;
> case 'I':
> corrupt_item = 1;
> + break;
> case 'd':
> delete = 1;
> break;
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/6] btrfs-progs: corrupt block, add break after option U
2014-12-19 16:06 ` [PATCH 2/6] btrfs-progs: corrupt block, add break after option U David Sterba
@ 2014-12-19 16:49 ` Eric Sandeen
0 siblings, 0 replies; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:49 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> Resolves-Coverity-CID: 1258793
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> btrfs-corrupt-block.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
> index aeeb1b298f66..b477e878376b 100644
> --- a/btrfs-corrupt-block.c
> +++ b/btrfs-corrupt-block.c
> @@ -1068,6 +1068,7 @@ int main(int ac, char **av)
> break;
> case 'U':
> chunk_tree = 1;
> + break;
> case 'i':
> inode = arg_strtou64(optarg);
> break;
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/6] btrfs-progs: fragments, close output file on error
2014-12-19 16:06 ` [PATCH 3/6] btrfs-progs: fragments, close output file on error David Sterba
@ 2014-12-19 16:50 ` Eric Sandeen
0 siblings, 0 replies; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:50 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> Resolves-Coverity-CID: 1258794
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> btrfs-fragments.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/btrfs-fragments.c b/btrfs-fragments.c
> index d03c2c3e7319..360f10f87bfa 100644
> --- a/btrfs-fragments.c
> +++ b/btrfs-fragments.c
> @@ -233,7 +233,7 @@ list_fragments(int fd, u64 flags, char *dir)
> ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
> if (ret < 0) {
> fprintf(stderr, "ERROR: can't perform the search\n");
> - return ret;
> + goto out_close;
> }
> /* the ioctl returns the number of item it found in nr_items */
> if (sk->nr_items == 0)
> @@ -373,7 +373,10 @@ skip:;
> fprintf(html, "</p>");
> }
> fprintf(html, "</body></html>\n");
> -
> +
> +out_close:
> + fclose(html);
> +
> return ret;
> }
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/6] btrfs-progs: check result of first_cache_extent
2014-12-19 16:06 ` [PATCH 4/6] btrfs-progs: check result of first_cache_extent David Sterba
@ 2014-12-19 16:56 ` Eric Sandeen
2014-12-19 17:03 ` David Sterba
0 siblings, 1 reply; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:56 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> If the tree's empty, we'll get NULL and dereference it.
Hm, but this is under an explicit check for not empty:
while (!cache_tree_empty(roots_info_cache)) {
sooo? Maybe it's just defensive? Nothing really wrong
with being defensive, I suppose, so:
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> Resolves-Coverity-CID: 1248828
> Signed-off-by: David Sterba <dsterba@suse.cz>
> ---
> cmds-check.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/cmds-check.c b/cmds-check.c
> index 6eea36c2f52c..3e7a4ebdce44 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c
> @@ -8075,6 +8075,8 @@ static void free_roots_info_cache(void)
> struct root_item_info *rii;
>
> entry = first_cache_extent(roots_info_cache);
> + if (!entry)
> + break;
> remove_cache_extent(roots_info_cache, entry);
> rii = container_of(entry, struct root_item_info, cache_extent);
> free(rii);
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source
2014-12-19 16:06 ` [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source David Sterba
@ 2014-12-19 16:58 ` Eric Sandeen
0 siblings, 0 replies; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:58 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> Resolves-Coverity-CID: 1054894
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> cmds-send.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/cmds-send.c b/cmds-send.c
> index b17b5e2ca666..9b32c1f0e624 100644
> --- a/cmds-send.c
> +++ b/cmds-send.c
> @@ -172,11 +172,16 @@ out:
> return ret;
> }
>
> -static void add_clone_source(struct btrfs_send *s, u64 root_id)
> +static int add_clone_source(struct btrfs_send *s, u64 root_id)
> {
> s->clone_sources = realloc(s->clone_sources,
> sizeof(*s->clone_sources) * (s->clone_sources_count + 1));
> +
> + if (!s->clone_sources)
> + return -ENOMEM;
> s->clone_sources[s->clone_sources_count++] = root_id;
> +
> + return 0;
> }
>
> static int write_buf(int fd, const void *buf, int size)
> @@ -475,7 +480,11 @@ int cmd_send(int argc, char **argv)
> goto out;
> }
>
> - add_clone_source(&send, root_id);
> + ret = add_clone_source(&send, root_id);
> + if (ret < 0) {
> + fprintf(stderr, "ERROR: not enough memory\n");
> + goto out;
> + }
> subvol_uuid_search_finit(&send.sus);
> free(subvol);
> subvol = NULL;
> @@ -575,7 +584,11 @@ int cmd_send(int argc, char **argv)
> goto out;
> }
>
> - add_clone_source(&send, parent_root_id);
> + ret = add_clone_source(&send, parent_root_id);
> + if (ret < 0) {
> + fprintf(stderr, "ERROR: not enough memory\n");
> + goto out;
> + }
> }
>
> for (i = optind; i < argc; i++) {
> @@ -671,7 +684,11 @@ int cmd_send(int argc, char **argv)
> goto out;
>
> /* done with this subvol, so add it to the clone sources */
> - add_clone_source(&send, root_id);
> + ret = add_clone_source(&send, root_id);
> + if (ret < 0) {
> + fprintf(stderr, "ERROR: not enough memory\n");
> + goto out;
> + }
>
> parent_root_id = 0;
> full_send = 0;
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL
2014-12-19 16:06 ` [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL David Sterba
@ 2014-12-19 16:58 ` Eric Sandeen
0 siblings, 0 replies; 14+ messages in thread
From: Eric Sandeen @ 2014-12-19 16:58 UTC (permalink / raw)
To: David Sterba, linux-btrfs
On 12/19/14 10:06 AM, David Sterba wrote:
> Same in kernel and matches semantics of free().
>
> Resolves-Coverity-CID: 1054881
> Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> ctree.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/ctree.c b/ctree.c
> index bd6cb125b2a2..589efa3db17e 100644
> --- a/ctree.c
> +++ b/ctree.c
> @@ -48,6 +48,8 @@ struct btrfs_path *btrfs_alloc_path(void)
>
> void btrfs_free_path(struct btrfs_path *p)
> {
> + if (!p)
> + return;
> btrfs_release_path(p);
> kfree(p);
> }
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/6] btrfs-progs: check result of first_cache_extent
2014-12-19 16:56 ` Eric Sandeen
@ 2014-12-19 17:03 ` David Sterba
0 siblings, 0 replies; 14+ messages in thread
From: David Sterba @ 2014-12-19 17:03 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
On Fri, Dec 19, 2014 at 10:56:41AM -0600, Eric Sandeen wrote:
> On 12/19/14 10:06 AM, David Sterba wrote:
> > If the tree's empty, we'll get NULL and dereference it.
>
> Hm, but this is under an explicit check for not empty:
>
> while (!cache_tree_empty(roots_info_cache)) {
>
> sooo? Maybe it's just defensive? Nothing really wrong
> with being defensive, I suppose, so:
Well, mostly to shut up the warning with a minimal change. It could be
rewritten to
while ((entry = ...)) { ... }
as in other places.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-12-19 17:03 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-19 16:06 [PATCH 0/6] Btrfs progs, coverity fixes for 3.18 David Sterba
2014-12-19 16:06 ` [PATCH 1/6] btrfs-progs: corrupt block, add missing break to option I David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 2/6] btrfs-progs: corrupt block, add break after option U David Sterba
2014-12-19 16:49 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 3/6] btrfs-progs: fragments, close output file on error David Sterba
2014-12-19 16:50 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 4/6] btrfs-progs: check result of first_cache_extent David Sterba
2014-12-19 16:56 ` Eric Sandeen
2014-12-19 17:03 ` David Sterba
2014-12-19 16:06 ` [PATCH 5/6] btrfs-progs: check allocation result in add_clone_source David Sterba
2014-12-19 16:58 ` Eric Sandeen
2014-12-19 16:06 ` [PATCH 6/6] btrfs-progs: let btrfs_free_path accept NULL David Sterba
2014-12-19 16:58 ` Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).