Skip to content

Commit b8eb075

Browse files
committed
Using clang-tidy to start polishing the codebase.
1 parent 1538a50 commit b8eb075

File tree

17 files changed

+171
-41
lines changed

17 files changed

+171
-41
lines changed

.clang-tidy

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Checks: '
2+
*,
3+
-altera-*,
4+
-android-*,
5+
bugprone-*,
6+
-bugprone-branch-clone,
7+
-bugprone-easily-swappable-parameters,
8+
-bugprone-integer-division,
9+
-bugprone-macro-parentheses,
10+
-bugprone-narrowing-conversions,
11+
cert-*,
12+
-cert-err33-c,
13+
-cert-err34-c,
14+
-cert-msc30-c,
15+
-cert-msc50-cpp,
16+
clang-analyzer-*,
17+
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
18+
-clang-analyzer-valist.Uninitialized,
19+
-concurrency-mt-unsafe,
20+
-cppcoreguidelines-avoid-magic-numbers,
21+
-cppcoreguidelines-avoid-non-const-global-variables,
22+
-cppcoreguidelines-init-variables,
23+
-cppcoreguidelines-narrowing-conversions,
24+
-google-readability-casting,
25+
-hicpp-signed-bitwise,
26+
llvm-*,
27+
-llvm-include-order,
28+
-llvmlibc-restrict-system-libc-headers,
29+
misc-*,
30+
-misc-redundant-expression,
31+
-misc-unused-parameters,
32+
modernize-*,
33+
-modernize-avoid-c-arrays,
34+
-modernize-deprecated-headers,
35+
-modernize-loop-convert,
36+
-modernize-use-auto,
37+
-modernize-use-nullptr,
38+
-modernize-use-trailing-return-type,
39+
-modernize-use-using,
40+
performance-*,
41+
portability-*,
42+
readability-*,
43+
-readability-function-cognitive-complexity,
44+
-readability-function-size,
45+
-readability-identifier-length,
46+
-readability-implicit-bool-conversion,
47+
-readability-inconsistent-declaration-parameter-name,
48+
-readability-isolate-declaration,
49+
-readability-magic-numbers,
50+
-readability-simplify-boolean-expr'

include/proxy/ssh/cipher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mod_proxy.h"
2929

3030
#if defined(PR_USE_OPENSSL)
31+
#include <openssl/evp.h>
3132

3233
int proxy_ssh_cipher_init(void);
3334
int proxy_ssh_cipher_free(void);

include/proxy/ssh/mac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH MAC API
3-
* Copyright (c) 2021-2022 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
2929
#include "proxy/ssh/packet.h"
3030

3131
#if defined(PR_USE_OPENSSL)
32+
#include <openssl/evp.h>
3233

3334
int proxy_ssh_mac_init(void);
3435
int proxy_ssh_mac_free(void);

lib/proxy/db.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy database implementation
3-
* Copyright (c) 2015-2024 TJ Saunders
3+
* Copyright (c) 2015-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -108,6 +108,9 @@ static void db_sql(void *user_data, sqlite3 *db, const char *info,
108108
pr_trace_msg(trace_channel, 1, "(sqlite3): closed database: %s",
109109
sqlite3_db_filename(db, "main"));
110110
break;
111+
112+
default:
113+
break;
111114
}
112115
}
113116
#endif /* SQLITE_CONFIG_SQLLOG */

lib/proxy/ftp/msg.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy FTP message routines
3-
* Copyright (c) 2013-2021 TJ Saunders
3+
* Copyright (c) 2013-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -444,6 +444,9 @@ const pr_netaddr_t *proxy_ftp_msg_parse_ext_addr(pool *p, const char *msg,
444444

445445
break;
446446
}
447+
448+
default:
449+
break;
447450
}
448451

449452
/* Advance past the address portion of the argument. */

lib/proxy/ftp/sess.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy FTP session routines
3-
* Copyright (c) 2013-2023 TJ Saunders
3+
* Copyright (c) 2013-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -574,6 +574,9 @@ int proxy_ftp_sess_send_pbsz_prot(pool *p,
574574
send_prot = TRUE;
575575
}
576576
break;
577+
578+
default:
579+
break;
577580
}
578581

579582
if (send_prot == TRUE) {

lib/proxy/reverse.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy reverse proxy implementation
3-
* Copyright (c) 2012-2022 TJ Saunders
3+
* Copyright (c) 2012-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -1584,26 +1584,33 @@ int proxy_reverse_connect_get_policy_id(const char *policy) {
15841584

15851585
if (strcasecmp(policy, "Random") == 0) {
15861586
return PROXY_REVERSE_CONNECT_POLICY_RANDOM;
1587+
}
15871588

1588-
} else if (strcasecmp(policy, "RoundRobin") == 0) {
1589+
if (strcasecmp(policy, "RoundRobin") == 0) {
15891590
return PROXY_REVERSE_CONNECT_POLICY_ROUND_ROBIN;
1591+
}
15901592

1591-
} else if (strcasecmp(policy, "Shuffle") == 0) {
1593+
if (strcasecmp(policy, "Shuffle") == 0) {
15921594
return PROXY_REVERSE_CONNECT_POLICY_SHUFFLE;
1595+
}
15931596

1594-
} else if (strcasecmp(policy, "LeastConns") == 0) {
1597+
if (strcasecmp(policy, "LeastConns") == 0) {
15951598
return PROXY_REVERSE_CONNECT_POLICY_LEAST_CONNS;
1599+
}
15961600

1597-
} else if (strcasecmp(policy, "PerUser") == 0) {
1601+
if (strcasecmp(policy, "PerUser") == 0) {
15981602
return PROXY_REVERSE_CONNECT_POLICY_PER_USER;
1603+
}
15991604

1600-
} else if (strcasecmp(policy, "PerGroup") == 0) {
1605+
if (strcasecmp(policy, "PerGroup") == 0) {
16011606
return PROXY_REVERSE_CONNECT_POLICY_PER_GROUP;
1607+
}
16021608

1603-
} else if (strcasecmp(policy, "PerHost") == 0) {
1609+
if (strcasecmp(policy, "PerHost") == 0) {
16041610
return PROXY_REVERSE_CONNECT_POLICY_PER_HOST;
1611+
}
16051612

1606-
} else if (strcasecmp(policy, "LeastResponseTime") == 0) {
1613+
if (strcasecmp(policy, "LeastResponseTime") == 0) {
16071614
return PROXY_REVERSE_CONNECT_POLICY_LEAST_RESPONSE_TIME;
16081615
}
16091616

lib/proxy/ssh.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH implementation
3-
* Copyright (c) 2021-2022 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@ static const char *trace_channel = "proxy.ssh";
7070

7171
static unsigned long ssh_opts = 0UL;
7272

73-
static void ssh_ssh2_read_poll_ev(const void *, void *);
73+
static void ssh_ssh2_read_poll_ev(const void *event_data, void *user_data);
7474

7575
static int ssh_get_server_version(pool *p,
7676
const struct proxy_session *proxy_sess) {

lib/proxy/ssh/agent.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH agent support
3-
* Copyright (c) 2021-2023 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -69,6 +69,9 @@ static int agent_failure(char resp_status) {
6969
case PROXY_SSHCOM_AGENT_FAILURE:
7070
failed = TRUE;
7171
break;
72+
73+
default:
74+
break;
7275
}
7376

7477
return failed;

lib/proxy/ssh/cipher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static unsigned int write_cipher_idx = 0;
9898

9999
static const char *trace_channel = "proxy.ssh.cipher";
100100

101-
static void clear_cipher(struct proxy_ssh_cipher *);
101+
static void clear_cipher(struct proxy_ssh_cipher *cipher);
102102

103103
static unsigned int get_next_read_index(void) {
104104
if (read_cipher_idx == 1) {

lib/proxy/ssh/kex.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ProFTPD - mod_proxy SSH key exchange (kex)
3-
* Copyright (c) 2021-2023 TJ Saunders
3+
* Copyright (c) 2021-2025 TJ Saunders
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -298,8 +298,9 @@ static const char *kex_server_version = NULL;
298298
static unsigned char kex_digest_buf[EVP_MAX_MD_SIZE];
299299

300300
/* Necessary prototypes. */
301-
static struct proxy_ssh_packet *read_kex_packet(pool *, struct proxy_ssh_kex *,
302-
conn_t *, int, char *, unsigned int, ...);
301+
static struct proxy_ssh_packet *read_kex_packet(pool *p,
302+
struct proxy_ssh_kex *kex, conn_t *conn, int disconnect_code,
303+
char *found_msg_type, unsigned int ntypes, ...);
303304

304305
static const char *trace_channel = "proxy.ssh.kex";
305306

@@ -1562,7 +1563,8 @@ static const char *get_preferred_name(pool *p, const char *names) {
15621563
register unsigned int i;
15631564

15641565
/* Advance to the first comma, or NUL. */
1565-
for (i = 0; names[i] && names[i] != ','; i++);
1566+
for (i = 0; names[i] && names[i] != ','; i++) {
1567+
}
15661568

15671569
if (names[i] == ',' ||
15681570
names[i] == '\0') {
@@ -4858,41 +4860,48 @@ static int run_kex(struct proxy_ssh_kex *kex, conn_t *conn) {
48584860
strcmp(algo, "diffie-hellman-group16-sha512") == 0 ||
48594861
strcmp(algo, "diffie-hellman-group18-sha512") == 0) {
48604862
return handle_kex_dh(kex, conn);
4863+
}
48614864

4862-
} else if (strcmp(algo, "diffie-hellman-group-exchange-sha1") == 0) {
4865+
if (strcmp(algo, "diffie-hellman-group-exchange-sha1") == 0) {
48634866
return handle_kex_dh_gex(kex, conn);
4867+
}
48644868

4865-
} else if (strcmp(algo, "rsa1024-sha1") == 0) {
4869+
if (strcmp(algo, "rsa1024-sha1") == 0) {
48664870
return handle_kex_rsa(kex, conn);
4871+
}
48674872

48684873
#if ((OPENSSL_VERSION_NUMBER > 0x000907000L && defined(OPENSSL_FIPS)) || \
48694874
(OPENSSL_VERSION_NUMBER > 0x000908000L)) && \
48704875
defined(HAVE_SHA256_OPENSSL)
4871-
} else if (strcmp(algo, "diffie-hellman-group-exchange-sha256") == 0) {
4876+
if (strcmp(algo, "diffie-hellman-group-exchange-sha256") == 0) {
48724877
return handle_kex_dh_gex(kex, conn);
4878+
}
48734879

4874-
} else if (strcmp(algo, "rsa2048-sha256") == 0) {
4880+
if (strcmp(algo, "rsa2048-sha256") == 0) {
48754881
return handle_kex_rsa(kex, conn);
4882+
}
48764883
#endif
48774884

48784885
#if defined(PR_USE_OPENSSL_ECC)
4879-
} else if (strcmp(algo, "ecdh-sha2-nistp256") == 0 ||
4880-
strcmp(algo, "ecdh-sha2-nistp384") == 0 ||
4881-
strcmp(algo, "ecdh-sha2-nistp521") == 0) {
4886+
if (strcmp(algo, "ecdh-sha2-nistp256") == 0 ||
4887+
strcmp(algo, "ecdh-sha2-nistp384") == 0 ||
4888+
strcmp(algo, "ecdh-sha2-nistp521") == 0) {
48824889
return handle_kex_ecdh(kex, conn);
4890+
}
48834891
#endif /* PR_USE_OPENSSL_ECC */
48844892

48854893
#if defined(PR_USE_SODIUM) && defined(HAVE_SHA256_OPENSSL)
4886-
} else if (strcmp(algo, "curve25519-sha256") == 0 ||
4887-
strcmp(algo, "[email protected]") == 0) {
4894+
if (strcmp(algo, "curve25519-sha256") == 0 ||
4895+
strcmp(algo, "[email protected]") == 0) {
48884896
return handle_kex_curve25519(kex, conn);
4897+
}
48894898
#endif /* PR_USE_SODIUM and HAVE_SHA256_OPENSSL */
48904899

48914900
#if defined(HAVE_X448_OPENSSL) && defined(HAVE_SHA512_OPENSSL)
4892-
} else if (strcmp(algo, "curve448-sha512") == 0) {
4901+
if (strcmp(algo, "curve448-sha512") == 0) {
48934902
return handle_kex_curve448(kex, conn);
4894-
#endif /* HAVE_X448_OPENSSL and HAVE_SHA512_OPENSSL */
48954903
}
4904+
#endif /* HAVE_X448_OPENSSL and HAVE_SHA512_OPENSSL */
48964905

48974906
(void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION,
48984907
"unsupported key exchange algorithm '%s'", algo);

lib/proxy/ssh/keys.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ static void prepare_provider_fds(int stdout_fd, int stderr_fd) {
262262
pr_signals_handle();
263263
(void) close(i);
264264
}
265-
266-
return;
267265
}
268266

269267
static void prepare_provider_pipes(int *stdout_pipe, int *stderr_pipe) {
@@ -2891,6 +2889,9 @@ static int handle_hostkey(pool *p, EVP_PKEY *pkey,
28912889
}
28922890

28932891
break;
2892+
2893+
default:
2894+
break;
28942895
}
28952896

28962897
break;
@@ -4631,6 +4632,9 @@ static const unsigned char *ecdsa_sign_data(pool *p, const unsigned char *data,
46314632
case NID_secp521r1:
46324633
proxy_ssh_msg_write_string(&buf, &buflen, "ecdsa-sha2-nistp521");
46334634
break;
4635+
4636+
default:
4637+
break;
46344638
}
46354639

46364640
proxy_ssh_msg_write_data(&buf, &buflen, sig_ptr, (sig_bufsz - sig_buflen),
@@ -4880,6 +4884,9 @@ int proxy_ssh_keys_verify_pubkey_type(pool *p, unsigned char *pubkey_data,
48804884
case NID_secp521r1:
48814885
res = (pubkey_type == PROXY_SSH_KEY_ECDSA_521);
48824886
break;
4887+
4888+
default:
4889+
break;
48834890
}
48844891
}
48854892
break;

lib/proxy/ssh/mac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static size_t mac_blockszs[2] = { 0, 0 };
9090
static unsigned int read_mac_idx = 0;
9191
static unsigned int write_mac_idx = 0;
9292

93-
static void clear_mac(struct proxy_ssh_mac *);
93+
static void clear_mac(struct proxy_ssh_mac *mac);
9494

9595
static unsigned int get_next_read_index(void) {
9696
if (read_mac_idx == 1) {

lib/proxy/ssh/packet.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,6 @@ static void read_packet_discard(conn_t *conn) {
605605
flags = PROXY_SSH_PACKET_READ_FL_PESSIMISTIC;
606606
proxy_ssh_packet_conn_read(conn, buf, buflen, flags);
607607
}
608-
609-
return;
610608
}
611609

612610
static int read_packet_len(conn_t *conn, struct proxy_ssh_packet *pkt,
@@ -1004,6 +1002,9 @@ const char *proxy_ssh_packet_get_msg_type_desc(unsigned char msg_type) {
10041002

10051003
case PROXY_SSH_MSG_CHANNEL_FAILURE:
10061004
return "SSH_MSG_CHANNEL_FAILURE";
1005+
1006+
default:
1007+
break;
10071008
}
10081009

10091010
return "(unknown)";

0 commit comments

Comments
 (0)