* [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once
@ 2026-11-12 10:10 Jakob-Tobias Winter
2026-11-13 8:56 ` Christian Ebner
2026-11-14 21:27 ` applied: " Thomas Lamprecht
0 siblings, 2 replies; 3+ messages in thread
From: Jakob-Tobias Winter @ 2026-11-12 10:10 UTC (permalink / raw)
To: pbs-devel; +Cc: Jakob-Tobias Winter
Array parameters, for example 'group-filter', are set by giving the
parameter once per value. The command line parser collects the values of
a repeated parameter in an array, while the 'api' subcommands expected a
single string for each parameter and panicked with "entered unreachable
code". So array parameters could only be passed with one value.
Hand each value over to the parameter verification separately. Array
parameters now accept more than one value, and other parameters that are
given more than once get rejected as duplicate instead of causing a
panic.
Anything other than a string or an array of strings cannot come from the
command line parser. Such a value was the other way to reach that panic,
and parameters that are no object at all were ignored. Return an error
for both, and add tests for all of these cases.
Signed-off-by: Jakob-Tobias Winter <tobias@stuttgart.de>
---
changes since v1, thanks to Christian for the review:
* return an error for a value that is no string, where unreachable!()
was left, and for parameters that are no object, which were ignored
* add regression tests. Without the fix they fail: on master with the
panic, on v1 for parameters that are no object.
v1: https://lore.proxmox.com/pbs-devel/20261109215938.903397-1-tobias@stuttgart.de/
Reproducer:
proxmox-backup-debug api create /config/tape-backup-job --id two \
--store store1 --pool pool1 --drive drive1 \
--group-filter type:vm --group-filter group:ct/200
Tested with release builds of current master (68577e654) and
proxmox-backup-api and proxmox-backup-proxy running, over HTTP and
in-process (PROXMOX_DEBUG_API_CODE=1): without the patch each call with
a repeated parameter panics. With it array parameters given more than
once reach the API, as JSON body (create) and as query string (set,
get), and calls without a repeated parameter print the same as before.
cargo test --workspace passes, cargo fmt --check and clippy report
nothing new.
src/bin/proxmox_backup_debug/api.rs | 138 ++++++++++++++++++++++++++--
1 file changed, 128 insertions(+), 10 deletions(-)
diff --git a/src/bin/proxmox_backup_debug/api.rs b/src/bin/proxmox_backup_debug/api.rs
index 61cd1b7db..ec6701357 100644
--- a/src/bin/proxmox_backup_debug/api.rs
+++ b/src/bin/proxmox_backup_debug/api.rs
@@ -152,16 +152,24 @@ fn merge_parameters(
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
- if let Some(Value::Object(map)) = param {
- param_list.extend(map.into_iter().map(|(k, v)| {
- (
- k,
- match v {
- Value::String(s) => s,
- _ => unreachable!(), // we're in the CLI
- },
- )
- }));
+ if let Some(param) = param {
+ let Value::Object(map) = param else {
+ bail!("expected the parameters as an object, got '{param}'");
+ };
+ for (key, value) in map {
+ // the command line parser collects the values of a parameter that is given
+ // more than once in an array
+ let values = match value {
+ Value::Array(values) => values,
+ value => vec![value],
+ };
+ for value in values {
+ let Value::String(text) = value else {
+ bail!("parameter '{key}': expected a string, got '{value}'");
+ };
+ param_list.push((key.clone(), text));
+ }
+ }
}
let params = schema.parse_parameter_strings(¶m_list, true)?;
@@ -505,3 +513,113 @@ pub fn api_commands() -> CommandLineInterface {
cmd_def.into()
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ use proxmox_schema::{ArraySchema, ObjectSchema, StringSchema};
+
+ const PARAMETERS: ObjectSchema = ObjectSchema::new(
+ "Parameters of a made up API call.",
+ &[
+ (
+ "id",
+ false,
+ &StringSchema::new("Part of the path.").schema(),
+ ),
+ ("name", true, &StringSchema::new("A value.").schema()),
+ (
+ "tag",
+ true,
+ &ArraySchema::new("A list.", &StringSchema::new("An item.").schema()).schema(),
+ ),
+ ],
+ );
+
+ /// Parse a command line like the 'api' subcommands do and return what is left for
+ /// the called API method
+ fn cli_param(args: &[&str]) -> Value {
+ let fixed_param = HashMap::from([("method", "get".to_string())]);
+ let (mut param, remaining) = parse_arguments(
+ args,
+ &["api-path"],
+ &fixed_param,
+ API_METHOD_API_CALL.parameters,
+ )
+ .expect("parsing the command line failed");
+ assert!(remaining.is_empty());
+
+ let map = param.as_object_mut().unwrap();
+ map.remove("method");
+ map.remove("api-path");
+ param
+ }
+
+ fn merge(param: Option<Value>) -> Result<Value, Error> {
+ let uri_param = HashMap::from([("id".to_string(), "one".to_string())]);
+ merge_parameters(&uri_param, param, ParameterSchema::from(&PARAMETERS))
+ }
+
+ #[test]
+ fn test_merge_parameters() -> Result<(), Error> {
+ assert_eq!(merge(None)?, json!({ "id": "one" }));
+ assert_eq!(merge(Some(cli_param(&["/path"])))?, json!({ "id": "one" }));
+
+ let param = cli_param(&["/path", "--name", "a", "--tag", "b"]);
+ assert_eq!(
+ merge(Some(param))?,
+ json!({ "id": "one", "name": "a", "tag": ["b"] })
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn test_merge_parameters_given_more_than_once() -> Result<(), Error> {
+ let param = cli_param(&["/path", "--tag", "a", "--tag", "b", "--tag", "c"]);
+ assert_eq!(param, json!({ "tag": ["a", "b", "c"] }));
+ assert_eq!(
+ merge(Some(param))?,
+ json!({ "id": "one", "tag": ["a", "b", "c"] })
+ );
+
+ // only an array can take more than one value
+ let param = cli_param(&["/path", "--name", "a", "--name", "b"]);
+ let err = merge(Some(param)).expect_err("second value for a string should fail");
+ assert!(
+ err.to_string().contains("'name': duplicate parameter"),
+ "unexpected error: {err}"
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn test_merge_parameters_unexpected_input() {
+ // the command line parser produces none of these, they have to fail without panic
+ for param in [json!(null), json!("a"), json!(["a"])] {
+ let err = merge(Some(param)).expect_err("parameters that are no object should fail");
+ assert!(
+ err.to_string()
+ .contains("expected the parameters as an object"),
+ "unexpected error: {err}"
+ );
+ }
+
+ for (name, param) in [
+ ("name", json!({ "name": 1 })),
+ ("name", json!({ "name": null })),
+ ("name", json!({ "name": { "a": "b" } })),
+ ("tag", json!({ "tag": ["a", 1] })),
+ ("tag", json!({ "tag": [["a"]] })),
+ ] {
+ let err = merge(Some(param)).expect_err("value that is no string should fail");
+ assert!(
+ err.to_string()
+ .contains(&format!("parameter '{name}': expected a string")),
+ "unexpected error: {err}"
+ );
+ }
+ }
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once
2026-11-12 10:10 [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once Jakob-Tobias Winter
@ 2026-11-13 8:56 ` Christian Ebner
2026-11-14 21:27 ` applied: " Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Christian Ebner @ 2026-11-13 8:56 UTC (permalink / raw)
To: Jakob-Tobias Winter, pbs-devel
On 11/12/26 11:17 AM, Jakob-Tobias Winter wrote:
> Array parameters, for example 'group-filter', are set by giving the
> parameter once per value. The command line parser collects the values of
> a repeated parameter in an array, while the 'api' subcommands expected a
> single string for each parameter and panicked with "entered unreachable
> code". So array parameters could only be passed with one value.
>
> Hand each value over to the parameter verification separately. Array
> parameters now accept more than one value, and other parameters that are
> given more than once get rejected as duplicate instead of causing a
> panic.
>
> Anything other than a string or an array of strings cannot come from the
> command line parser. Such a value was the other way to reach that panic,
> and parameters that are no object at all were ignored. Return an error
> for both, and add tests for all of these cases.
>
> Signed-off-by: Jakob-Tobias Winter <tobias@stuttgart.de>
> ---
> changes since v1, thanks to Christian for the review:
> * return an error for a value that is no string, where unreachable!()
> was left, and for parameters that are no object, which were ignored
> * add regression tests. Without the fix they fail: on master with the
> panic, on v1 for parameters that are no object.
>
> v1: https://lore.proxmox.com/pbs-devel/20261109215938.903397-1-tobias@stuttgart.de/
Thanks for the revised version of the patch and including some
regression test: change look good to me now.
Spot checked the array grouping now works correctly and does not lead to
a panic and tests cover relevant cases.
Reviewed-by: Christian Ebner <c.ebner@proxmox.com>
Tested-by: Christian Ebner <c.ebner@proxmox.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* applied: [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once
2026-11-12 10:10 [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once Jakob-Tobias Winter
2026-11-13 8:56 ` Christian Ebner
@ 2026-11-14 21:27 ` Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2026-11-14 21:27 UTC (permalink / raw)
To: pbs-devel, Jakob-Tobias Winter
On Thu, 12 Nov 2026 11:10:30 +0100, Jakob-Tobias Winter wrote:
> Array parameters, for example 'group-filter', are set by giving the
> parameter once per value. The command line parser collects the values of
> a repeated parameter in an array, while the 'api' subcommands expected a
> single string for each parameter and panicked with "entered unreachable
> code". So array parameters could only be passed with one value.
>
> Hand each value over to the parameter verification separately. Array
> parameters now accept more than one value, and other parameters that are
> given more than once get rejected as duplicate instead of causing a
> panic.
>
> [...]
Applied, thanks!
[1/1] bin: debug: api: fix panic on parameters given more than once
commit: 53a3e6289fd8b8211c93d8fb06472fdee7f4ff92
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-14 21:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 10:10 [PATCH proxmox-backup v2] bin: debug: api: fix panic on parameters given more than once Jakob-Tobias Winter
2026-11-13 8:56 ` Christian Ebner
2026-11-14 21:27 ` applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox