diff --git a/lib/setup.c b/lib/setup.c index 58cc8534..1599ab78 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -175,12 +175,15 @@ void logger(struct crypt_device *cd, int level, const char *file, { va_list argp; char target[LOG_MAX_LEN + 2]; + int len; va_start(argp, format); - if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0 ) { + len = vsnprintf(&target[0], LOG_MAX_LEN, format, argp); + if (len > 0 && len < LOG_MAX_LEN) { /* All verbose and error messages in tools end with EOL. */ - if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR) + if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR || + level == CRYPT_LOG_DEBUG || level == CRYPT_LOG_DEBUG_JSON) strncat(target, "\n", LOG_MAX_LEN); crypt_log(cd, level, target); diff --git a/src/utils_tools.c b/src/utils_tools.c index cf0728c0..3d4025a9 100644 --- a/src/utils_tools.c +++ b/src/utils_tools.c @@ -116,7 +116,7 @@ void tool_log(int level, const char *msg, void *usrptr __attribute__((unused))) case CRYPT_LOG_DEBUG_JSON: case CRYPT_LOG_DEBUG: if (opt_debug) - fprintf(stdout, "# %s\n", msg); + fprintf(stdout, "# %s", msg); break; } }