Skip to content

Commit 4b5a6b1

Browse files
committed
use snprintf instead of sprintf
- move _snprintf define to const.h - bump to 2.4.16.7dev Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 090239d commit 4b5a6b1

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
12/10/2024
2+
- github: add SonarQube analysis to Github workflows
3+
- code: use snprintf instead of sprintf
4+
- code: move _snprintf define to const.h
5+
- bump to 2.4.16.7dev
6+
17
12/09/2024
28
- release 2.4.16.6
39

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([mod_auth_openidc],[2.4.16.6],[[email protected]])
1+
AC_INIT([mod_auth_openidc],[2.4.16.7dev],[[email protected]])
22

33
AC_SUBST(NAMEVER, AC_PACKAGE_TARNAME()-AC_PACKAGE_VERSION())
44

src/const.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ static inline int _oidc_str_to_int(const char *s, const int default_value) {
104104
return v;
105105
}
106106

107+
#ifdef WIN32
108+
#define snprintf _snprintf
109+
#endif
110+
107111
#define HAVE_APACHE_24 MODULE_MAGIC_NUMBER_MAJOR >= 20100714
108112

109113
#ifndef OIDC_DEBUG

src/jose.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767
#include <openssl/core_names.h>
6868
#endif
6969

70-
#ifdef WIN32
71-
#define snprintf _snprintf
72-
#endif
73-
7470
#include "util.h"
7571

7672
/*

src/metrics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static oidc_metrics_bucket_t _oidc_metric_buckets[] = {
237237
*/
238238
static inline char *_json_int2str(apr_pool_t *pool, json_int_t n) {
239239
char s[255];
240-
sprintf(s, "%" JSON_INTEGER_FORMAT, n);
240+
snprintf(s, 255, "%" JSON_INTEGER_FORMAT, n);
241241
return apr_pstrdup(pool, s);
242242
}
243243

test/test.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,54 +61,54 @@ static int TST_RC;
6161
#define TST_ASSERT(message, expression) \
6262
TST_RC = (expression); \
6363
if (!TST_RC) { \
64-
sprintf(TST_ERR_MSG, TST_FORMAT("%d"), __FUNCTION__, message, TST_RC, 1); \
64+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%d"), __FUNCTION__, message, TST_RC, 1); \
6565
return TST_ERR_MSG; \
6666
}
6767

6868
#define TST_ASSERT_ERR(message, expression, pool, err) \
6969
TST_RC = (expression); \
7070
if (!TST_RC) { \
71-
sprintf(TST_ERR_MSG, TST_FORMAT("%d") " %s", __FUNCTION__, message, TST_RC, 1, \
72-
oidc_jose_e2s(pool, err)); \
71+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%d") " %s", __FUNCTION__, message, TST_RC, 1, \
72+
oidc_jose_e2s(pool, err)); \
7373
return TST_ERR_MSG; \
7474
}
7575

7676
#define TST_ASSERT_CJOSE_ERR(message, expression, pool, cjose_err) \
7777
TST_RC = (expression); \
7878
if (!TST_RC) { \
79-
sprintf(TST_ERR_MSG, TST_FORMAT("%d") " %s", __FUNCTION__, message, TST_RC, 1, \
80-
oidc_cjose_e2s(pool, cjose_err)); \
79+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%d") " %s", __FUNCTION__, message, TST_RC, 1, \
80+
oidc_cjose_e2s(pool, cjose_err)); \
8181
return TST_ERR_MSG; \
8282
}
8383

8484
#define TST_ASSERT_STR(message, result, expected) \
8585
TST_RC = \
8686
(result && expected) ? (_oidc_strcmp(result, expected) != 0) : ((result != NULL) || (expected != NULL)); \
8787
if (TST_RC) { \
88-
sprintf(TST_ERR_MSG, TST_FORMAT("%s"), __FUNCTION__, message, result ? result : "(null)", \
89-
expected ? expected : "(null)"); \
88+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%s"), __FUNCTION__, message, result ? result : "(null)", \
89+
expected ? expected : "(null)"); \
9090
return TST_ERR_MSG; \
9191
}
9292

9393
#define TST_ASSERT_STRN(message, result, expected, len) \
9494
TST_RC = (result && expected) ? (_oidc_strncmp(result, expected, len) != 0) \
9595
: ((result != NULL) || (expected != NULL)); \
9696
if (TST_RC) { \
97-
sprintf(TST_ERR_MSG, TST_FORMAT("%s"), __FUNCTION__, message, result ? result : "(null)", \
98-
expected ? expected : "(null)"); \
97+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%s"), __FUNCTION__, message, result ? result : "(null)", \
98+
expected ? expected : "(null)"); \
9999
return TST_ERR_MSG; \
100100
}
101101

102102
#define TST_ASSERT_LONG(message, result, expected) \
103103
if (result != expected) { \
104-
sprintf(TST_ERR_MSG, TST_FORMAT("%ld"), __FUNCTION__, message, result, expected); \
104+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%ld"), __FUNCTION__, message, result, expected); \
105105
return TST_ERR_MSG; \
106106
}
107107

108108
#define TST_ASSERT_BYTE(message, result, expected) \
109109
if (result != expected) { \
110-
sprintf(TST_ERR_MSG, TST_FORMAT("%s"), __FUNCTION__, message, result ? "TRUE" : "FALSE", \
111-
expected ? "TRUE" : "FALSE"); \
110+
snprintf(TST_ERR_MSG, 4096, TST_FORMAT("%s"), __FUNCTION__, message, result ? "TRUE" : "FALSE", \
111+
expected ? "TRUE" : "FALSE"); \
112112
return TST_ERR_MSG; \
113113
}
114114

@@ -140,8 +140,8 @@ static char *test_private_key_parse(apr_pool_t *pool) {
140140
const char ecPrivateKeyFile[512];
141141

142142
char *dir = getenv("srcdir") ? getenv("srcdir") : ".";
143-
sprintf((char *)rsaPrivateKeyFile, "%s/%s", dir, "/test/private.pem");
144-
sprintf((char *)ecPrivateKeyFile, "%s/%s", dir, "/test/ecpriv.key");
143+
snprintf((char *)rsaPrivateKeyFile, 512, "%s/%s", dir, "/test/private.pem");
144+
snprintf((char *)ecPrivateKeyFile, 512, "%s/%s", dir, "/test/ecpriv.key");
145145

146146
input = BIO_new(BIO_s_file());
147147
TST_ASSERT_ERR("test_private_key_parse_BIO_new_RSA_private_key", input != NULL, pool, err);
@@ -204,9 +204,9 @@ static char *test_public_key_parse(apr_pool_t *pool) {
204204
const char certificateFile[512];
205205
const char ecCertificateFile[512];
206206
char *dir = getenv("srcdir") ? getenv("srcdir") : ".";
207-
sprintf((char *)publicKeyFile, "%s/%s", dir, "/test/public.pem");
208-
sprintf((char *)certificateFile, "%s/%s", dir, "/test/certificate.pem");
209-
sprintf((char *)ecCertificateFile, "%s/%s", dir, "/test/eccert.pem");
207+
snprintf((char *)publicKeyFile, 512, "%s/%s", dir, "/test/public.pem");
208+
snprintf((char *)certificateFile, 512, "%s/%s", dir, "/test/certificate.pem");
209+
snprintf((char *)ecCertificateFile, 512, "%s/%s", dir, "/test/eccert.pem");
210210

211211
input = BIO_new(BIO_s_file());
212212
TST_ASSERT_ERR("test_public_key_parse_BIO_new_public_key", input != NULL, pool, err);

0 commit comments

Comments
 (0)