After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 782681 - btrfs partitions mounted with whitespace cannot be resized
btrfs partitions mounted with whitespace cannot be resized
Status: RESOLVED FIXED
Product: gparted
Classification: Other
Component: application
0.25.0
Other Linux
: Normal normal
: ---
Assigned To: Mike Fleetwood
gparted maintainers alias
Depends on:
Blocks:
 
 
Reported: 2017-05-16 08:28 UTC by Marcel Waldvogel
Modified: 2017-08-07 17:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The details requested (2.00 KB, text/html)
2017-05-16 09:05 UTC, Marcel Waldvogel
  Details
Handle spaces in mount points (v1) (15.10 KB, patch)
2017-05-20 09:50 UTC, Mike Fleetwood
none Details | Review

Description Marcel Waldvogel 2017-05-16 08:28:47 UTC
Trying to resize a btrfs partition whose current mount point (and label) includes whitespace fails with "btrfs filesystem resize: too many arguments".

How to reproduce:
1. Have a btrfs partition with a name containing white space, which has been (auto)mounted to the path containing the label; in my case "/media/$USER/White Space Name".
2. In Gparted, right click on that partition, select "Move/resize", change the size, click apply.

Apparently, the mount point is passed unquoted the the shell.

Peeking at the code in https://git.gnome.org/browse/gparted/tree/src/btrfs.cc?h=GPARTED_0_25_0&id=976eea771c5374eca2ae845066577d222715de8e#n338 (the code looks similar in HEAD), there seem to be two problems:

* The code assumes a devid_str, but it deals with a mountpoint name.
* execute_command() receives a single string, not an array of arguments, requiring escaping of special characters.

Whitespace/shell metacharacter handling seems to be a general problem for all the `execute_command()` instances in this file. Is there no way to pass the arguments as an array, avoiding shell argument splitting?
Comment 1 Mike Fleetwood 2017-05-16 08:44:55 UTC
Hi Marcel,

In the Applying Pending Operations dialog please [Save Details] and
attach the file to this bug report.  I want to check I understand your
scenario exactly and this will tell me.

Thanks,
Mike
Comment 2 Marcel Waldvogel 2017-05-16 09:05:41 UTC
Created attachment 351950 [details]
The details requested

The unquoted execute_command() arguments should speak for themselves, but I'll happily comply if this gets the bug fixed faster.
Comment 3 Marcel Waldvogel 2017-05-16 09:08:55 UTC
Sorry, my mistake (and thus probably confusion). The devid_str is there as expected; it is the mount_point later which is the problem (also for other execute_command()s in this file).
Comment 4 Mike Fleetwood 2017-05-20 09:50:29 UTC
Created attachment 352205 [details] [review]
Handle spaces in mount points (v1)

Hi Curtis,

Here's the patchset to fix this.  It applies a deliberately simple and
therefore easy to validate rule of always enclosing mount points in
double quotes when used in command lines.  This applies to btrfs, jfs,
nilfs2, xfs and the Data Rescue dialog.  This was already done in
Win_GParted.cc for mounting and unmounting by this much earlier commit:

moved comment to correct position fixed issues with mountpoints containing
https://git.gnome.org/browse/gparted/commit/?id=85e9ddbf48a7870aa594df3d8d0e589cc348c936

LVM refues to create VGs and LVs with spaces in the names so can't be
affected.  LUKS mappings can be created with spaces in the name and this
breaks GParted's ability to look inside such open LUKS mapping.  This
will take more than adding a few quotes to fix so I haven't fixed it.

Also to answer Marcel's question: execute_command() could be converted
to use vectors of strings, especially as Glib::shell_parse_argv() is
used to parse the string into a vector of strings.  However with the
number of uses of execute_command() in the code, ~150, this is big job I
am not going to do that when quoting will do.  Also there are a few
cases where GParted does "sh -c 'command1 | command2'" because it can't
create 2 commands joined by a pipe.  So just passing a vector to
execute_command() will still have a single string with
"command1 | command2".

Thanks,
Mike
Comment 5 Curtis Gedak 2017-05-21 16:05:25 UTC
Hi Mike,

Thank you for patch set v1 in comment #4.  It looks good to me.  It is an improvement on the current code and helps to handle whitespace in mount points for a number of file systems.

I performed regression testing on Kubuntu 16.04 and discovered no problems.  Resize operations on btfs, jfs, nilfs2, and xfs performed as expected.  Copying an xfs partition to a smaller partition also continued to work.

As such I have committed this patch set v1 to the git master branch for inclusion in the next release of GParted.

The relevant git commits can be viewed at the following links:

Quote mount point when resizing btrfs (#782681)
https://git.gnome.org/browse/gparted/commit/?id=618c1a202d388fa4ab3da1c00ce1407ea73cbce6

Quote mount point when resizing jfs (#782681)
https://git.gnome.org/browse/gparted/commit/?id=3a10e30c3a79a2322dcbac7cea26d9209a2dd5c9

Quote mount point when resizing nilfs2 (#782681)
https://git.gnome.org/browse/gparted/commit/?id=988dacfb1bc2c47ecea01edc9203035f86c420aa

Quote mount point when copying and resizing xfs (#782681)
https://git.gnome.org/browse/gparted/commit/?id=2025581029eae816cf331918ddae42094d3600f1

Quote mount point in Data Rescue dialog (#782681)
https://git.gnome.org/browse/gparted/commit/?id=6798c271c76a128f356a1806772224d314381b1b

Update comment with example LUKS_Info cache entry
https://git.gnome.org/browse/gparted/commit/?id=e0390d9cd8b4f35b09b6a9f12becfcb7b7356b94

Thanks,
Curtis
Comment 6 Mike Fleetwood 2017-05-22 16:49:13 UTC
Hi Marcel,

Just in case you are not aware, there is a simple workaround until the
next release of GParted:
1) Unmount the file system (either in GParted or any other method);
2) Resize the inactive partition in GParted.

Mike
Comment 7 Curtis Gedak 2017-08-07 17:19:39 UTC
This enhancement was included in the GParted 0.29.0 release on August 7, 2017.