Skip to content

Commit 65853a4

Browse files
committed
fixes, coddling, and suppressions for clang-tidy complaints:
examples/pem/pem.c: fix stdio stream leaks. src/ssl.c and src/ssl_load.c: suppress concurrency-mt-unsafe around getenv(). getenv() is threadsafe as long as no threads putenv() or setenv(). wolfssl/openssl/asn1.h: add parentheses to fix bugprone-macro-parentheses in ASN1_EX_TEMPLATE_TYPE(), and suppress misfiring bugprone-macro-parentheses around IMPLEMENT_ASN1_FUNCTIONS().
1 parent ee7f02b commit 65853a4

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

examples/pem/pem.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,13 @@ int main(int argc, char* argv[])
10241024
if (ret < 0) {
10251025
fprintf(stderr, "%s\n", wc_GetErrorString(ret));
10261026
}
1027+
1028+
if (in_file != stdin)
1029+
(void)fclose(in_file);
1030+
1031+
if (out_file != stdout)
1032+
(void)fclose(out_file);
1033+
10271034
return (ret == 0) ? 0 : 1;
10281035
}
10291036

src/ssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23984,7 +23984,7 @@ int wolfSSL_RAND_seed(const void* seed, int len)
2398423984
*/
2398523985
const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2398623986
{
23987-
#if !defined(NO_FILESYSTEM) && defined(XGETENV)
23987+
#if !defined(NO_FILESYSTEM) && defined(XGETENV) && !defined(NO_GETENV)
2398823988
char* rt;
2398923989

2399023990
WOLFSSL_ENTER("wolfSSL_RAND_file_name");
@@ -23995,6 +23995,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2399523995

2399623996
XMEMSET(fname, 0, len);
2399723997

23998+
/* // NOLINTBEGIN(concurrency-mt-unsafe) */
2399823999
if ((rt = XGETENV("RANDFILE")) != NULL) {
2399924000
if (len > XSTRLEN(rt)) {
2400024001
XMEMCPY(fname, rt, XSTRLEN(rt));
@@ -24004,13 +24005,15 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2400424005
rt = NULL;
2400524006
}
2400624007
}
24008+
/* // NOLINTEND(concurrency-mt-unsafe) */
2400724009

2400824010
/* $RANDFILE was not set or is too large, check $HOME */
2400924011
if (rt == NULL) {
2401024012
const char ap[] = "/.rnd";
2401124013

2401224014
WOLFSSL_MSG("Environment variable RANDFILE not set");
2401324015

24016+
/* // NOLINTBEGIN(concurrency-mt-unsafe) */
2401424017
if ((rt = XGETENV("HOME")) == NULL) {
2401524018
#ifdef XALTHOMEVARNAME
2401624019
if ((rt = XGETENV(XALTHOMEVARNAME)) == NULL) {
@@ -24023,6 +24026,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2402324026
return NULL;
2402424027
#endif
2402524028
}
24029+
/* // NOLINTEND(concurrency-mt-unsafe) */
2402624030

2402724031
if (len > XSTRLEN(rt) + XSTRLEN(ap)) {
2402824032
fname[0] = '\0';

src/ssl_load.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5099,7 +5099,7 @@ int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa)
50995099
int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
51005100
{
51015101
int ret;
5102-
#ifdef XGETENV
5102+
#if defined(XGETENV) && !defined(NO_GETENV)
51035103
char* certDir = NULL;
51045104
char* certFile = NULL;
51055105
word32 flags = 0;
@@ -5109,7 +5109,8 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
51095109

51105110
WOLFSSL_ENTER("wolfSSL_CTX_set_default_verify_paths");
51115111

5112-
#ifdef XGETENV
5112+
#if defined(XGETENV) && !defined(NO_GETENV)
5113+
/* // NOLINTBEGIN(concurrency-mt-unsafe) */
51135114
certDir = wc_strdup_ex(XGETENV("SSL_CERT_DIR"), DYNAMIC_TYPE_TMP_BUFFER);
51145115
certFile = wc_strdup_ex(XGETENV("SSL_CERT_FILE"), DYNAMIC_TYPE_TMP_BUFFER);
51155116
flags = WOLFSSL_LOAD_FLAG_PEM_CA_ONLY;
@@ -5133,6 +5134,7 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
51335134
ret = 0;
51345135
}
51355136
}
5137+
/* // NOLINTEND(concurrency-mt-unsafe) */
51365138
else
51375139
#endif
51385140

@@ -5157,7 +5159,7 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
51575159
#endif
51585160
}
51595161

5160-
#ifdef XGETENV
5162+
#if defined(XGETENV) && !defined(NO_GETENV)
51615163
XFREE(certFile, NULL, DYNAMIC_TYPE_TMP_BUFFER);
51625164
XFREE(certDir, NULL, DYNAMIC_TYPE_TMP_BUFFER);
51635165
#endif

wolfssl/openssl/asn1.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ typedef struct WOLFSSL_ASN1_ITEM WOLFSSL_ASN1_ITEM;
270270
(WolfsslAsn1FreeCb)member_type##_free, \
271271
(WolfsslAsn1i2dCb)i2d_##member_type, \
272272
(WolfsslAsn1d2iCb)d2i_##member_type, \
273-
0, flags & ASN1_TFLG_TAG_MASK ? tag : -1, 0, \
274-
!!(flags & ASN1_TFLG_EXPLICIT), TRUE }
273+
0, (flags) & ASN1_TFLG_TAG_MASK ? (tag) : -1, 0, \
274+
!!((flags) & ASN1_TFLG_EXPLICIT), TRUE }
275275

276276
WOLFSSL_API void *wolfSSL_ASN1_item_new(const WOLFSSL_ASN1_ITEM *tpl);
277277
WOLFSSL_API void wolfSSL_ASN1_item_free(void *obj,
@@ -282,7 +282,7 @@ WOLFSSL_API void* wolfSSL_ASN1_item_d2i(void** dst, const byte **src, long len,
282282
const WOLFSSL_ASN1_ITEM* item);
283283

284284
/* Need function declaration otherwise compiler complains */
285-
/* // NOLINTBEGIN(readability-named-parameter) */
285+
/* // NOLINTBEGIN(readability-named-parameter,bugprone-macro-parentheses) */
286286
#define IMPLEMENT_ASN1_FUNCTIONS(type) \
287287
type *type##_new(void); \
288288
type *type##_new(void){ \
@@ -303,7 +303,7 @@ WOLFSSL_API void* wolfSSL_ASN1_item_d2i(void** dst, const byte **src, long len,
303303
return (type*)wolfSSL_ASN1_item_d2i((void**)dst, src, len, \
304304
&type##_template_data); \
305305
}
306-
/* // NOLINTEND(readability-named-parameter) */
306+
/* // NOLINTEND(readability-named-parameter,bugprone-macro-parentheses) */
307307

308308
#endif /* OPENSSL_ALL */
309309

0 commit comments

Comments
 (0)