Skip to content

Commit 706441c

Browse files
vthiebaut10tgauth
andauthored
Handle some codeQL warnings and errors (#645)
* Handle com codeql warnings and errors * Handle additional codeql errors and warnings * Add comment to changes made on upstream code Co-authored-by: Tess Gauthier <[email protected]> * Fix diplicated return statement Co-authored-by: Tess Gauthier <[email protected]>
1 parent 76af855 commit 706441c

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

auth-options.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ sshauthopt_parse(const char *opts, const char **errstrp)
415415
goto alloc_fail;
416416
}
417417
l = (size_t)(tmp - opt);
418-
cp[l] = '\0'; /* truncate at '=' */
418+
cp[l] = '\0'; /* truncate at '=' */ // CodeQL [SM02311] false positive: l is calculated so that it is never out of bounds.
419419
if (!valid_env_name(cp)) {
420420
free(cp);
421421
free(opt);
@@ -425,7 +425,7 @@ sshauthopt_parse(const char *opts, const char **errstrp)
425425
/* Check for duplicates; XXX O(n*log(n)) */
426426
for (i = 0; i < ret->nenv; i++) {
427427
if (strncmp(ret->env[i], cp, l) == 0 &&
428-
ret->env[i][l] == '=')
428+
ret->env[i][l] == '=') // CodeQL [SM02311] false positive: l is calculated so that it is never out of bounds.
429429
break;
430430
}
431431
free(cp);

auth2-pubkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ format_key(const struct sshkey *key)
7979
char *ret, *fp = sshkey_fingerprint(key,
8080
options.fingerprint_hash, SSH_FP_DEFAULT);
8181

82-
xasprintf(&ret, "%s %s", sshkey_type(key), fp);
82+
xasprintf(&ret, "%s %s", sshkey_type(key), fp); // CodeQL [SM02311] false positive: xasprintf handles case when fp is null.
8383
free(fp);
8484
return ret;
8585
}

contrib/win32/win32compat/misc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ am_system()
16021602

16031603
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &proc_token) == FALSE ||
16041604
GetTokenInformation(proc_token, TokenUser, NULL, 0, &info_len) == TRUE ||
1605-
(info = (TOKEN_USER*)malloc(info_len)) == NULL) {
1605+
(info = (TOKEN_USER*)malloc(info_len)) == NULL) { // CodeQL [SM02320]: GetTokenInformation will initialize info
16061606
fatal("unable to know if I am running as system");
16071607
}
16081608

@@ -1747,7 +1747,7 @@ get_sid(const char* name)
17471747
goto cleanup;
17481748
}
17491749

1750-
if ((info = (TOKEN_USER*)malloc(info_len)) == NULL) {
1750+
if ((info = (TOKEN_USER*)malloc(info_len)) == NULL) { // CodeQL [SM02320]: GetTokenInformation will initialize info
17511751
errno = ENOMEM;
17521752
goto cleanup;
17531753
};

packet.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,9 @@ ssh_packet_read_poll2_mux(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
14491449
return SSH_ERR_INTERNAL_ERROR;
14501450
*typep = SSH_MSG_NONE;
14511451
cp = sshbuf_ptr(state->input);
1452+
if (cp == NULL) { // fix CodeQL SM02311
1453+
return SSH_ERR_INTERNAL_ERROR;
1454+
}
14521455
if (state->packlen == 0) {
14531456
if (sshbuf_len(state->input) < 4 + 1)
14541457
return 0; /* packet is incomplete */

readpass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ notify_start(int force_askpass, const char *fmt, ...)
318318
fatal_f("stdfd_devnull failed");
319319
closefrom(STDERR_FILENO + 1);
320320
setenv("SSH_ASKPASS_PROMPT", "none", 1); /* hint to UI */
321-
execlp(askpass, askpass, prompt, (char *)NULL);
321+
execlp(askpass, askpass, prompt, (char *)NULL); // CodeQL [SM01925] false positive: Command strings are controlled by application.
322322
error_f("exec(%s): %s", askpass, strerror(errno));
323323
_exit(1);
324324
/* NOTREACHED */

regress/unittests/win32compat/file_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void file_simple_fileio()
193193
retValue = lseek(f, offset, SEEK_SET);
194194
ASSERT_INT_EQ(retValue, 0);
195195
char *tmp = dup_str(small_read_buf);
196-
ASSERT_PTR_NE(tmp, NULL);
196+
ASSERT_PTR_NE(tmp, NULL); // CodeQL [SM02311] false positive: ASSERT_PTR_NE is checking if tmp is NULL.
197197

198198
retValue = read(f, small_read_buf, SMALL_RECV_BUF_SIZE);
199199
small_read_buf[retValue] = '\0';

ssh-keygen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ parse_hex_u64(const char *s, uint64_t *up)
19431943
unsigned long long ull;
19441944

19451945
errno = 0;
1946-
ull = strtoull(s, &ep, 16);
1946+
ull = strtoull(s, &ep, 16); // CodeQL [SM02313] false positive: strtoull will initialize ep.
19471947
if (*s == '\0' || *ep != '\0')
19481948
fatal("Invalid certificate time: not a number");
19491949
if (errno == ERANGE && ull == ULONG_MAX)
@@ -3211,7 +3211,7 @@ do_download_sk(const char *skprovider, const char *device)
32113211
/* Save the key with the application string as the comment */
32123212
if (pass == NULL)
32133213
pass = private_key_passphrase();
3214-
if ((r = sshkey_save_private(key, path, pass,
3214+
if ((r = sshkey_save_private(key, path, pass, // CodeQL [SM02311] false positive: private_key_passphrase() will never return null.
32153215
key->sk_application, private_key_format,
32163216
openssh_format_cipher, rounds)) != 0) {
32173217
error_r(r, "Saving key \"%s\" failed", path);
@@ -3932,7 +3932,7 @@ main(int argc, char **argv)
39323932
}
39333933

39343934
/* Save the key with the given passphrase and comment. */
3935-
if ((r = sshkey_save_private(private, identity_file, passphrase,
3935+
if ((r = sshkey_save_private(private, identity_file, passphrase, // CodeQL [SM02311] false positive: private_key_passphrase() will never return null.
39363936
comment, private_key_format, openssh_format_cipher, rounds)) != 0) {
39373937
error_r(r, "Saving key \"%s\" failed", identity_file);
39383938
freezero(passphrase, strlen(passphrase));

sshconnect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host,
168168
* Execute the proxy command.
169169
* Note that we gave up any extra privileges above.
170170
*/
171-
execv(argv[0], argv);
171+
execv(argv[0], argv); // CodeQL [SM01925] false positive: Command strings are controlled by application.
172172
perror(argv[0]);
173173
exit(1);
174174
}

sshconnect2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ ssh_kex2(struct ssh *ssh, char *host, struct sockaddr *hostaddr, u_short port,
247247
/* Expand or fill in HostkeyAlgorithms */
248248
all_key = sshkey_alg_list(0, 0, 1, ',');
249249
if ((r = kex_assemble_names(&options.hostkeyalgorithms,
250-
kex_default_pk_alg(), all_key)) != 0)
250+
kex_default_pk_alg(), all_key)) != 0) // CodeQL [SM02311] false positive: kex_assemble_names handle null all_key.
251251
fatal_fr(r, "kex_assemble_namelist");
252252
free(all_key);
253253

0 commit comments

Comments
 (0)