Skip to content

Commit

Permalink
Add error to query message #32
Browse files Browse the repository at this point in the history
  • Loading branch information
claucece committed Dec 14, 2017
1 parent fa8fb42 commit 2b34fd1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/otrv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/test/test_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b34fd1

Please sign in to comment.