Skip to content

Commit 3a6a311

Browse files
olszomalmtrojnar
authored andcommitted
Add GCC printf format checking for logging functions
1 parent 200fbe9 commit 3a6a311

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/libp11-int.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ extern char *pkcs11_strdup(char *, size_t);
157157
#define EVP_PKEY_get0_EC_KEY(key) ((key)->pkey.ec)
158158
#endif
159159

160-
extern void pkcs11_log(PKCS11_CTX_private *pctx, int level, const char *format, ...);
160+
extern void pkcs11_log(PKCS11_CTX_private *pctx, int level, const char *format, ...)
161+
#ifdef __GNUC__
162+
__attribute__((format(printf, 3, 4)))
163+
#endif
164+
;
161165

162166
/* Reinitializing the module after fork (if detected) */
163167
extern unsigned int get_forkid(void);

src/provider.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ typedef struct {
150150
/* Utility functions */
151151
/******************************************************************************/
152152

153+
#ifdef __GNUC__
154+
__attribute__((format(printf, 6, 7)))
155+
#endif
153156
static void PROVIDER_CTX_log(PROVIDER_CTX *prov_ctx, int level, int reason, int line, const char *file, const char *format, ...)
154157
{
155158
va_list args;
@@ -735,13 +738,13 @@ static int store_load(void *ctx, OSSL_CALLBACK *object_cb, void *object_cbarg,
735738
int len = i2d_X509(cert, NULL);
736739

737740
if (len < 0) {
738-
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 4, OPENSSL_LINE, OPENSSL_FUNC, store_ctx->uri);
741+
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 4, OPENSSL_LINE, OPENSSL_FUNC, "%s", store_ctx->uri);
739742
X509_free(cert);
740743
return 0;
741744
}
742745
tmp = data = OPENSSL_malloc((size_t)len);
743746
if (!tmp) {
744-
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 1, OPENSSL_LINE, OPENSSL_FUNC, store_ctx->uri);
747+
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 1, OPENSSL_LINE, OPENSSL_FUNC, "%s", store_ctx->uri);
745748
X509_free(cert);
746749
return 0;
747750
}
@@ -755,7 +758,7 @@ static int store_load(void *ctx, OSSL_CALLBACK *object_cb, void *object_cbarg,
755758

756759
if (!object_cb(params, object_cbarg)) {
757760
/* callback failed */
758-
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 5, OPENSSL_LINE, OPENSSL_FUNC, store_ctx->uri);
761+
PROVIDER_CTX_log(store_ctx->prov_ctx, LOG_ERR, 5, OPENSSL_LINE, OPENSSL_FUNC, "%s", store_ctx->uri);
759762
OPENSSL_free(data);
760763
return 0;
761764
}

0 commit comments

Comments
 (0)