btrfs-progs: qgroup: fix qgroup show sort by multi items
diff mbox

Message ID 20171026083251.13454-1-lufq.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Lu Fengqi Oct. 26, 2017, 8:32 a.m. UTC
We should not free the string until we don't call strtok any longer.

If the string is freed in advance, in fact, the second and subsequent
sort items will be ignored.

Fixes: 9fcdf8f8945b ("btrfs-progs: don't write to optarg in btrfs_qgroup_parse_sort_string")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 qgroup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

David Sterba Oct. 26, 2017, 6:04 p.m. UTC | #1
On Thu, Oct 26, 2017 at 04:32:51PM +0800, Lu Fengqi wrote:
> We should not free the string until we don't call strtok any longer.
> 
> If the string is freed in advance, in fact, the second and subsequent
> sort items will be ignored.
> 
> Fixes: 9fcdf8f8945b ("btrfs-progs: don't write to optarg in btrfs_qgroup_parse_sort_string")
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>

Huh, what an old bug, thanks for the fix.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/qgroup.c b/qgroup.c
index fffdbb12..7e8ef079 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -1222,7 +1222,8 @@  int btrfs_qgroup_parse_sort_string(const char *opt_arg,
 	if (!opt_tmp)
 		return -ENOMEM;
 
-	while ((p = strtok(opt_tmp, ",")) != NULL) {
+	p = strtok(opt_tmp, ",");
+	while (p) {
 		flag = 0;
 		ptr_argv = all_sort_items;
 
@@ -1262,8 +1263,7 @@  int btrfs_qgroup_parse_sort_string(const char *opt_arg,
 			}
 			btrfs_qgroup_setup_comparer(comps, what_to_sort, order);
 		}
-		free(opt_tmp);
-		opt_tmp = NULL;
+		p = strtok(NULL, ",");
 	}
 
 out: