Skip to content

Commit b391e8e

Browse files
committed
Fix C transport command truncation warning
1 parent 06b386d commit b391e8e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

bin/blackbelt-c.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void shell_quote(const char *src, char *dst, size_t size) {
5959
static int save_and_transport(const char *response_path, const char *requested_path) {
6060
if (getenv("BBEA_NO_SAVE") && !strcmp(getenv("BBEA_NO_SAVE"), "1") && !requested_path) return 0;
6161

62-
char helper[4096], quoted[8192], command[12288];
62+
char helper[4096], quoted[8192], command[24576];
6363
const char *helper_path = output_helper(helper, sizeof(helper));
6464
shell_quote(helper_path, quoted, sizeof(quoted));
6565

@@ -97,8 +97,14 @@ static int save_and_transport(const char *response_path, const char *requested_p
9797
}
9898

9999
if (getenv("BBEA_TRANSPORT") && *getenv("BBEA_TRANSPORT")) {
100-
char qpath[8192]; shell_quote(requested_path ? requested_path : response_path, qpath, sizeof(qpath));
101-
snprintf(command, sizeof(command), "bash %s %s", quoted, qpath);
100+
const char *transport_path = requested_path ? requested_path : response_path;
101+
char qpath[8192];
102+
shell_quote(transport_path, qpath, sizeof(qpath));
103+
int written = snprintf(command, sizeof(command), "bash %s %s", quoted, qpath);
104+
if (written < 0 || (size_t)written >= sizeof(command)) {
105+
fprintf(stderr, "Transport command is too long.\n");
106+
return 6;
107+
}
102108
if (system(command) != 0) return 6;
103109
}
104110
return 0;

0 commit comments

Comments
 (0)