Skip to content

Commit

Permalink
Merge pull request #3089 from cgwalters/fix-undeploy-parsing
Browse files Browse the repository at this point in the history
undeploy: Parse integer more properly
  • Loading branch information
cgwalters authored Nov 9, 2023
2 parents e4b82c4 + c3cf5b2 commit 2c774de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ostree/ot-admin-builtin-undeploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invoc
g_autoptr (GPtrArray) current_deployments = ostree_sysroot_get_deployments (sysroot);

const char *deploy_index_str = argv[1];
int deploy_index = atoi (deploy_index_str);
guint deploy_index;
{
char *endptr = NULL;
errno = 0;
deploy_index = (guint)g_ascii_strtoull (deploy_index_str, &endptr, 10);
if (*endptr != '\0')
return glnx_throw (error, "Invalid index: %s", deploy_index_str);
}

g_autoptr (OstreeDeployment) target_deployment
= ot_admin_get_indexed_deployment (sysroot, deploy_index, error);
Expand Down
8 changes: 7 additions & 1 deletion tests/admin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set -euo pipefail

echo "1..$((30 + ${extra_admin_tests:-0}))"
echo "1..$((31 + ${extra_admin_tests:-0}))"

mkdir sysrootmin
${CMD_PREFIX} ostree admin init-fs --modern sysrootmin
Expand Down Expand Up @@ -187,6 +187,12 @@ ${CMD_PREFIX} ostree admin status
validate_bootloader
echo "ok deploy with modified /etc"

if ${CMD_PREFIX} ostree admin undeploy blah 2>err.txt; then
fatal "undeploy parsed string"
fi
assert_file_has_content_literal err.txt 'error: Invalid index: blah'
echo "ok undeploy error invalid int"

# we now have 5 deployments, let's bring that back down to 1
for i in $(seq 4); do
${CMD_PREFIX} ostree admin undeploy 0
Expand Down

0 comments on commit 2c774de

Please sign in to comment.