Bug 268686

Summary: freebsd-update cannot handle spaces in file paths
Product: Base System Reporter: 06-birds-herald
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: emaste
Priority: ---    
Version: 13.1-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Modifications to freebsd-update to make it work with spaces in the file paths none

Description 06-birds-herald 2022-12-31 22:33:42 UTC
Created attachment 239169 [details]
Modifications to freebsd-update to make it work with spaces in the file paths

If freebsd-update is run with the -b -d or -f options followed by a path with a space, freebsd-update prints its usage and exits instead of updating. This is because it further splits arguments by spaces into more arguments internally, causing it to incorrectly parse them. There are also problems with the internal handling of the $BASEDIR and other path variables. This makes it difficult to update certain installations, for example a jail located at a non-root location with a space in its path.

This can be fixed by simply adding quotes to the necessary locations in the script, and changing the use of xargs in one location. I have attached a diff of what I had to do to get it to work for my usage (fetch, upgrade, and install). certctl, which is run by freebsd-update, also has a problem with spaces and would also need to be fixed in a similar manner.

The script also doesn't return a nonzero error code upon failure to parse its arguments.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2023-03-03 00:06:08 UTC
Would you mind attaching a git format patch, so that we can preserve the appropriate metadata (in particular, your author details), or if you already have a GitHub account you can submit as a pull request there.

Alternatively, I can commit the change with a "Submitted by" tag with your preferred author info.
Comment 2 Ed Maste freebsd_committer freebsd_triage 2023-09-29 19:48:33 UTC
-		WORKDIR=$1
+		WORKDIR="$1"

This isn't necessary; spaces in $1 will be retained when assigning WORKDIR. Same for BASEDIR=$1 and perhaps other cases in the file. Quotes are indeed needed on e.g. [ -z "${BASEDIR}" ].