Skip to contentSkip to conversation

btrfs-progs: qgroup: check null in comparing paths

PATCH In review Sidong Yang 3 participants 3 messages Oct 8, 2023 – Oct 9, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: qgroup: check null in comparing paths

This patch fixes a bug that could occur when comparing paths in showing qgroups list. Old code doesn't check it and the bug occur when there is stale qgroup its path is null. This patch checkes whether it is null and return without comparing paths.

Issue: #687

---
 cmds/qgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)
cmds/qgroup.c +8 -0
index d9104d1a..265c4910 100644
@@ -486,6 +486,14 @@ static int comp_entry_with_path(struct btrfs_qgroup *entry1,
 	if (ret)
 		goto out;
 
+	if (!p1) {
+		ret = p2 ? 1 : 0;
+		goto out;
+	} else if (!p2) {
+		ret = -1;
+		goto out;
+	}
+
 	while (*p1 && *p2) {
 		if (*p1 != *p2)
 			break;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Sidong Yang

This patch fixes a bug that could occur when comparing paths in showing qgroups list. Old code doesn't check it and the bug occur when there is stale qgroup its path is null. This patch checkes whether it is null and return without comparing paths.

Issue: #687

It's also a good chance to contribute a new patch to add such test case to btrfs-progs.

Feel free to ask for any help on creating such test case.

Thanks,
Qu

Quoted 23 lines
---
  cmds/qgroup.c | 8 ++++++++
  1 file changed, 8 insertions(+)
cmds/qgroup.c +8 -0
index d9104d1a..265c4910 100644
@@ -486,6 +486,14 @@ static int comp_entry_with_path(struct btrfs_qgroup *entry1,
  	if (ret)
  		goto out;
 
+	if (!p1) {
+		ret = p2 ? 1 : 0;
+		goto out;
+	} else if (!p2) {
+		ret = -1;
+		goto out;
+	}
+
  	while (*p1 && *p2) {
  		if (*p1 != *p2)
  			break;
#2 lore raw
In reply to Sidong Yang
Quoted 7 lines · Sidong Yang

This patch fixes a bug that could occur when comparing paths in showing qgroups list. Old code doesn't check it and the bug occur when there is stale qgroup its path is null. This patch checkes whether it is null and return without comparing paths.

Issue: #687

Added to devel, thanks. I've also added the test case.