Skip to content

Commit bb63077

Browse files
Moved aws_path_exist checks over to the safe variant. (awslabs#448)
1 parent 6d1801a commit bb63077

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

source/s2n/s2n_tls_channel_handler.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,71 @@ struct s2n_ctx {
6565
struct s2n_config *s2n_config;
6666
};
6767

68+
AWS_STATIC_STRING_FROM_LITERAL(s_debian_path, "/etc/ssl/certs");
69+
AWS_STATIC_STRING_FROM_LITERAL(s_rhel_path, "/etc/pki/tls/certs");
70+
AWS_STATIC_STRING_FROM_LITERAL(s_android_path, "/system/etc/security/cacerts");
71+
AWS_STATIC_STRING_FROM_LITERAL(s_free_bsd_path, "/usr/local/share/certs");
72+
AWS_STATIC_STRING_FROM_LITERAL(s_net_bsd_path, "/etc/openssl/certs");
73+
6874
static const char *s_determine_default_pki_dir(void) {
6975
/* debian variants */
70-
if (aws_path_exists("/etc/ssl/certs")) {
71-
return "/etc/ssl/certs";
76+
if (aws_path_exists(s_debian_path)) {
77+
return aws_string_c_str(s_debian_path);
7278
}
7379

7480
/* RHEL variants */
75-
if (aws_path_exists("/etc/pki/tls/certs")) {
76-
return "/etc/pki/tls/certs";
81+
if (aws_path_exists(s_rhel_path)) {
82+
return aws_string_c_str(s_rhel_path);
7783
}
7884

7985
/* android */
80-
if (aws_path_exists("/system/etc/security/cacerts")) {
81-
return "/system/etc/security/cacerts";
86+
if (aws_path_exists(s_android_path)) {
87+
return aws_string_c_str(s_android_path);
8288
}
8389

8490
/* Free BSD */
85-
if (aws_path_exists("/usr/local/share/certs")) {
86-
return "/usr/local/share/certs";
91+
if (aws_path_exists(s_free_bsd_path)) {
92+
return aws_string_c_str(s_free_bsd_path);
8793
}
8894

8995
/* Net BSD */
90-
if (aws_path_exists("/etc/openssl/certs")) {
91-
return "/etc/openssl/certs";
96+
if (aws_path_exists(s_net_bsd_path)) {
97+
return aws_string_c_str(s_net_bsd_path);
9298
}
9399

94100
return NULL;
95101
}
96102

103+
AWS_STATIC_STRING_FROM_LITERAL(s_debian_ca_file_path, "/etc/ssl/certs/ca-certificates.crt");
104+
AWS_STATIC_STRING_FROM_LITERAL(s_old_rhel_ca_file_path, "/etc/pki/tls/certs/ca-bundle.crt");
105+
AWS_STATIC_STRING_FROM_LITERAL(s_open_suse_ca_file_path, "/etc/ssl/ca-bundle.pem");
106+
AWS_STATIC_STRING_FROM_LITERAL(s_open_elec_ca_file_path, "/etc/pki/tls/cacert.pem");
107+
AWS_STATIC_STRING_FROM_LITERAL(s_modern_rhel_ca_file_path, "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem");
108+
97109
static const char *s_determine_default_pki_ca_file(void) {
98110
/* debian variants */
99-
if (aws_path_exists("/etc/ssl/certs/ca-certificates.crt")) {
100-
return "/etc/ssl/certs/ca-certificates.crt";
111+
if (aws_path_exists(s_debian_ca_file_path)) {
112+
return aws_string_c_str(s_debian_ca_file_path);
101113
}
102114

103115
/* Old RHEL variants */
104-
if (aws_path_exists("/etc/pki/tls/certs/ca-bundle.crt")) {
105-
return "/etc/pki/tls/certs/ca-bundle.crt";
116+
if (aws_path_exists(s_old_rhel_ca_file_path)) {
117+
return aws_string_c_str(s_old_rhel_ca_file_path);
106118
}
107119

108120
/* Open SUSE */
109-
if (aws_path_exists("/etc/ssl/ca-bundle.pem")) {
110-
return "/etc/ssl/ca-bundle.pem";
121+
if (aws_path_exists(s_open_suse_ca_file_path)) {
122+
return aws_string_c_str(s_open_suse_ca_file_path);
111123
}
112124

113125
/* Open ELEC */
114-
if (aws_path_exists("/etc/pki/tls/cacert.pem")) {
115-
return "/etc/pki/tls/cacert.pem";
126+
if (aws_path_exists(s_open_elec_ca_file_path)) {
127+
return aws_string_c_str(s_open_elec_ca_file_path);
116128
}
117129

118130
/* Modern RHEL variants */
119-
if (aws_path_exists("/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem")) {
120-
return "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem";
131+
if (aws_path_exists(s_modern_rhel_ca_file_path)) {
132+
return aws_string_c_str(s_modern_rhel_ca_file_path);
121133
}
122134

123135
return NULL;

0 commit comments

Comments
 (0)