Skip to content

Commit 99319f9

Browse files
soul2zimateclaude
andcommitted
fix: avoid passing empty string argument to skopeo when raw=false
Replace static array construction with ArrayList to conditionally add --raw, --authfile, and --daemon-host flags, preventing an empty string from being passed as a CLI argument. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1f70259 commit 99319f9

2 files changed

Lines changed: 22 additions & 44 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/image/ImageUtils.java

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -467,47 +467,32 @@ static Operations.ProcessExecOutput execSkopeoInspect(ImageRef imageRef, boolean
467467
var configPath = Environment.get(TRUSTIFY_DA_SKOPEO_CONFIG_PATH, "");
468468
var daemonHost = Environment.get(TRUSTIFY_DA_IMAGE_SERVICE_ENDPOINT, "");
469469

470-
String[] cmd;
470+
var cmdList = new java.util.ArrayList<String>();
471+
cmdList.add(skopeo);
472+
cmdList.add("inspect");
473+
474+
if (!configPath.isEmpty()) {
475+
cmdList.add("--authfile");
476+
cmdList.add(configPath);
477+
}
478+
479+
if (!daemonHost.isEmpty()) {
480+
cmdList.add("--daemon-host");
481+
cmdList.add(daemonHost);
482+
}
483+
484+
if (raw) {
485+
cmdList.add("--raw");
486+
}
487+
471488
if (daemonHost.isEmpty()) {
472-
cmd =
473-
configPath.isEmpty()
474-
? new String[] {
475-
skopeo,
476-
"inspect",
477-
raw ? "--raw" : "",
478-
String.format("docker://%s", imageRef.getImage().getFullName())
479-
}
480-
: new String[] {
481-
skopeo,
482-
"inspect",
483-
"--authfile",
484-
configPath,
485-
raw ? "--raw" : "",
486-
String.format("docker://%s", imageRef.getImage().getFullName())
487-
};
489+
cmdList.add(String.format("docker://%s", imageRef.getImage().getFullName()));
488490
} else {
489-
cmd =
490-
configPath.isEmpty()
491-
? new String[] {
492-
skopeo,
493-
"inspect",
494-
"--daemon-host",
495-
daemonHost,
496-
raw ? "--raw" : "",
497-
String.format("docker-daemon:%s", imageRef.getImage().getFullName())
498-
}
499-
: new String[] {
500-
skopeo,
501-
"inspect",
502-
"--authfile",
503-
configPath,
504-
"--daemon-host",
505-
daemonHost,
506-
raw ? "--raw" : "",
507-
String.format("docker-daemon:%s", imageRef.getImage().getFullName())
508-
};
491+
cmdList.add(String.format("docker-daemon:%s", imageRef.getImage().getFullName()));
509492
}
510493

494+
String[] cmd = cmdList.toArray(new String[0]);
495+
511496
return Operations.runProcessGetFullOutput(null, cmd, null);
512497
}
513498

src/test/java/io/github/guacsec/trustifyda/image/ImageUtilsTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ void test_get_image_digests_single() throws IOException {
229229
new String[] {
230230
"skopeo",
231231
"inspect",
232-
"",
233232
String.format("docker://%s", mockImageRef.getImage().getFullName())
234233
}),
235234
isNull()))
@@ -866,7 +865,6 @@ void test_exec_skopeo_inspect() {
866865
mockSkopeoConfig,
867866
"--daemon-host",
868867
mockSkopeoDaemon,
869-
"",
870868
String.format("docker-daemon:%s", mockImageRef.getImage().getFullName())
871869
}),
872870
isNull()))
@@ -898,7 +896,6 @@ void test_exec_skopeo_inspect_no_config() {
898896
"inspect",
899897
"--daemon-host",
900898
mockSkopeoDaemon,
901-
"",
902899
String.format("docker-daemon:%s", mockImageRef.getImage().getFullName())
903900
}),
904901
isNull()))
@@ -930,7 +927,6 @@ void test_exec_skopeo_inspect_no_daemon() {
930927
"inspect",
931928
"--authfile",
932929
mockSkopeoConfig,
933-
"",
934930
String.format("docker://%s", mockImageRef.getImage().getFullName())
935931
}),
936932
isNull()))
@@ -960,7 +956,6 @@ void test_exec_skopeo_inspect_no_config_no_daemon() {
960956
new String[] {
961957
"skopeo",
962958
"inspect",
963-
"",
964959
String.format("docker://%s", mockImageRef.getImage().getFullName())
965960
}),
966961
isNull()))
@@ -1062,7 +1057,6 @@ void test_get_single_image_digest() throws IOException {
10621057
new String[] {
10631058
"skopeo",
10641059
"inspect",
1065-
"",
10661060
String.format("docker://%s", mockImageRef.getImage().getFullName())
10671061
}),
10681062
isNull()))
@@ -1097,7 +1091,6 @@ void test_get_single_image_digest_empty() throws JsonProcessingException {
10971091
new String[] {
10981092
"skopeo",
10991093
"inspect",
1100-
"",
11011094
String.format("docker://%s", mockImageRef.getImage().getFullName())
11021095
}),
11031096
isNull()))

0 commit comments

Comments
 (0)