summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2016-06-01 20:50:38 +0200
committerAndreas Schneider <asn@cryptomilk.org>2016-06-02 07:32:27 +0200
commitd821fccad2cb0a0e0fc0de41fce6a2ee23df5367 (patch)
tree7a99366fb5c6fd5381087b59781b1e1100ace7b8
parentb2732b52202ae48f866a024c633466efdbb8e85a (diff)
downloadcmocka-d821fccad2cb0a0e0fc0de41fce6a2ee23df5367.tar.gz
cmocka-d821fccad2cb0a0e0fc0de41fce6a2ee23df5367.tar.bz2
cmocka-d821fccad2cb0a0e0fc0de41fce6a2ee23df5367.zip
vcm_print_error: fix segfault on long messages
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/cmocka.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 376acba..9300f04 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1720,11 +1720,12 @@ static void vcm_print_error(const char* const format, va_list args)
size_t msg_len = 0;
va_list ap;
int len;
+ va_copy(ap, args);
len = vsnprintf(buffer, sizeof(buffer), format, args);
if (len < 0) {
/* TODO */
- return;
+ goto end;
}
if (cm_error_message == NULL) {
@@ -1733,7 +1734,7 @@ static void vcm_print_error(const char* const format, va_list args)
cm_error_message = libc_malloc(len + 1);
if (cm_error_message == NULL) {
/* TODO */
- return;
+ goto end;
}
} else {
/* APPEND MESSAGE */
@@ -1742,7 +1743,7 @@ static void vcm_print_error(const char* const format, va_list args)
msg_len = strlen(cm_error_message);
tmp = libc_realloc(cm_error_message, msg_len + len + 1);
if (tmp == NULL) {
- return;
+ goto end;
}
cm_error_message = tmp;
}
@@ -1751,10 +1752,11 @@ static void vcm_print_error(const char* const format, va_list args)
/* Use len + 1 to also copy '\0' */
memcpy(cm_error_message + msg_len, buffer, len + 1);
} else {
- va_copy(ap, args);
vsnprintf(cm_error_message + msg_len, len, format, ap);
- va_end(ap);
}
+end:
+ va_end(ap);
+
}
static void vcm_free_error(char *err_msg)