Skip to content

Commit

Permalink
Used strcpy/strcat for vlog formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
olszomal committed Dec 18, 2024
1 parent 616ce86 commit d5ecf7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
24 changes: 12 additions & 12 deletions src/eng_back.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,19 @@ void ctx_log(ENGINE_CTX *ctx, int level, const char *format, ...)
va_start(args, format);
if (ctx->vlog) {
/* Log messages through a custom logging function */
va_list args_copy;
char *new_format = NULL;
int len = strlen("libp11: ") + strlen(format) + 1;
const char *prefix = "libp11: ";
char *vlog_format = OPENSSL_malloc(strlen(prefix) + strlen(format) + 1);

new_format = (char *)OPENSSL_malloc((size_t)len);
if (new_format == NULL) {
if (!vlog_format) {
va_end(args);
return;
}
va_copy(args_copy, args);
BIO_snprintf(new_format, (size_t)len, "libp11: %s", format);
ctx->vlog(level, (const char *)new_format, args_copy);
va_end(args_copy);
OPENSSL_free(new_format);
/* Copy and concatenate strings */
strcpy(vlog_format, prefix);
strcat(vlog_format, format);

ctx->vlog(level, (const char *)vlog_format, args);
OPENSSL_free(vlog_format);
} else if (level <= ctx->debug_level) {
vfprintf(stderr, format, args);
}
Expand All @@ -102,10 +101,11 @@ void ctx_log(ENGINE_CTX *ctx, int level, const char *format, ...)

static char *dump_hex(unsigned char *val, const size_t len)
{
char *hexbuf = NULL;
int i, j = 0, size = 2 * len + 1;
char *hexbuf = OPENSSL_malloc((size_t)size);

hexbuf = OPENSSL_malloc((size_t)size);
if (!hexbuf)
return NULL;
for (i = 0; i < len; i++) {
#ifdef WIN32
j += sprintf_s(hexbuf + j, size - j, "%02X", val[i]);
Expand Down
19 changes: 9 additions & 10 deletions src/p11_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,19 @@ void pkcs11_log(PKCS11_CTX *pctx, int level, const char *format, ...)
va_start(args, format);
if (pctx && PRIVCTX(pctx)->vlog_a) {
/* Log messages through a custom logging function */
va_list args_copy;
char *new_format = NULL;
int len = strlen("libp11: ") + strlen(format) + 1;
const char *prefix = "libp11: ";
char *vlog_format = OPENSSL_malloc(strlen(prefix) + strlen(format) + 1);

new_format = (char *)OPENSSL_malloc((size_t)len);
if (new_format == NULL) {
if (!vlog_format) {
va_end(args);
return;
}
va_copy(args_copy, args);
BIO_snprintf(new_format, (size_t)len, "libp11: %s", format);
PRIVCTX(pctx)->vlog_a(level, (const char *)new_format, args_copy);
va_end(args_copy);
OPENSSL_free(new_format);
/* Copy and concatenate strings */
strcpy(vlog_format, prefix);
strcat(vlog_format, format);

PRIVCTX(pctx)->vlog_a(level, (const char *)vlog_format, args);
OPENSSL_free(vlog_format);
} else if (level <= 3) { /* LOG_ERR */
vfprintf(stderr, format, args);
} else if (level >= 7) { /* LOG_DEBUG */
Expand Down

0 comments on commit d5ecf7c

Please sign in to comment.