Skip to content

Commit 5af611f

Browse files
committed
api,kvm: reject a mount option list that only looks empty
Validation returned early for a blank value, so a list of nothing but whitespace was accepted although whitespace is rejected everywhere else in the list. The two sides then disagreed about it: the restore wrapper treats it as no options at all, while the backup script sees a non empty string and hands it to mount as an option of its own. An empty value still clears the options, anything else is now validated. The array holding the mount command is also declared local, as arrays assigned in a bash function are otherwise global. mount_point and dest stay as they are, the callers of mount_operation read them.
1 parent 17b20fd commit 5af611f

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ private static void validateSafeMountCommandOptions(final Object param, final St
9090
return;
9191
}
9292
final String value = String.valueOf(param);
93-
if (StringUtils.isBlank(value)) {
93+
// An empty value clears the mount options and is allowed. A value that only looks empty is
94+
// not: whitespace is rejected everywhere else in the list, and the backup script would pass
95+
// it on to mount as an option of its own.
96+
if (value.isEmpty()) {
9497
return;
9598
}
9699

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ mount_operation() {
289289
if [ ${NAS_TYPE} == "cifs" ]; then
290290
MOUNT_OPTS="${MOUNT_OPTS},nobrl"
291291
fi
292-
mount_args=(-t "${NAS_TYPE}" "${NAS_ADDRESS}" "${mount_point}")
292+
local mount_args=(-t "${NAS_TYPE}" "${NAS_ADDRESS}" "${mount_point}")
293293
[[ -n "${MOUNT_OPTS}" ]] && mount_args+=(-o "${MOUNT_OPTS}")
294294
mount "${mount_args[@]}" 2>&1 | tee -a "$logFile"
295295
if [ $? -eq 0 ]; then

server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@ public void processMountOptionsParameter_RejectCephFsSecretWithCommandSubstituti
212212
paramProcessWorkerSpy.processParameters(cmd, params);
213213
}
214214

215+
@Test
216+
public void processMountOptionsParameter_AcceptsEmptyValueToClearTheOptions() {
217+
final HashMap<String, String> params = new HashMap<String, String>();
218+
params.put("mountOptions", "");
219+
final TestCmd cmd = new TestCmd();
220+
paramProcessWorkerSpy.processParameters(cmd, params);
221+
Assert.assertEquals("", cmd.mountOptions);
222+
}
223+
224+
@Test(expected = ServerApiException.class)
225+
public void processMountOptionsParameter_RejectWhitespaceOnly() {
226+
final HashMap<String, String> params = new HashMap<String, String>();
227+
// Only looks empty: the backup script would hand this to mount as an option.
228+
params.put("mountOptions", " ");
229+
final TestCmd cmd = new TestCmd();
230+
paramProcessWorkerSpy.processParameters(cmd, params);
231+
}
232+
215233
@Test(expected = ServerApiException.class)
216234
public void processMountOptionsParameter_RejectWhitespace() {
217235
final HashMap<String, String> params = new HashMap<String, String>();

0 commit comments

Comments
 (0)