Fix debugging messages callback.

The debug messages should contain EOL char.

Also check string lengths in internal logging macros.
This commit is contained in:
Milan Broz
2019-06-11 15:26:53 +02:00
parent df0faef9ca
commit 32258ee8ae
2 changed files with 6 additions and 3 deletions

View File

@@ -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);

View File

@@ -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;
}
}