From 2b34fd15b8376bf6bc1539b66cb56e6dedd99236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Celi?= Date: Thu, 14 Dec 2017 14:11:26 -0500 Subject: [PATCH] Add error to query message #32 --- src/client.c | 8 ++++++-- src/otrv4.c | 4 +++- src/test/test_api.c | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index 4f21d16f..172f02e3 100644 --- a/src/client.c +++ b/src/client.c @@ -316,9 +316,13 @@ char *otr4_client_query_message(const char *recipient, const char *message, if (!conv) return NULL; + // TODO: add name + ret = "Failed to start an Off-the-Record private conversation."; + // TODO: implement policy - // TODO: Check for errors when calling this function - otrv4_build_query_message(&ret, message, conv->conn); + if (otrv4_build_query_message(&ret, message, conv->conn)) + return ret; + return ret; } diff --git a/src/otrv4.c b/src/otrv4.c index cbd923ae..88694727 100644 --- a/src/otrv4.c +++ b/src/otrv4.c @@ -253,10 +253,12 @@ otrv4_err_t otrv4_build_query_message(string_t *dst, const string_t message, cursor = stpcpy(cursor, "? "); int rem = cursor - buff; + + /* Add '\0' */ if (*stpncpy(cursor, message, qm_size - rem)) { free(buff); buff = NULL; - return OTR4_ERROR; // could not zero-terminate the string + return OTR4_ERROR; /* could not zero-terminate the string */ } *dst = buff; diff --git a/src/test/test_api.c b/src/test/test_api.c index e78c5eeb..d71411cc 100644 --- a/src/test/test_api.c +++ b/src/test/test_api.c @@ -646,7 +646,8 @@ static void do_ake_otr3(otrv4_t *alice, otrv4_t *bob) { // Alice sends query message string_t query_message = NULL; - otrv4_build_query_message(&query_message, "", alice); + otrv4_assert(otrv4_build_query_message(&query_message, "", + alice) == OTR4_SUCCESS); otrv4_assert_cmpmem("?OTRv3", query_message, 6); // Bob receives query message