-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent memory leak in
xmpp_stanza_new_from_string()
Only remember the first stanza in case the string contains multiple stanzas. Signed-off-by: Steffen Jaeckel <[email protected]>
- Loading branch information
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ static void test_stanza_from_string(xmpp_ctx_t *ctx) | |
size_t buflen; | ||
int ret; | ||
|
||
static const char *str = | ||
const char *str = | ||
"<signcrypt xmlns=\"urn:xmpp:openpgp:0\"><to " | ||
"jid=\"[email protected]\"/><time " | ||
"stamp=\"2020-06-03T21:26:24+0200\"/><rpad/><payload><body " | ||
|
@@ -113,6 +113,22 @@ static void test_stanza_from_string(xmpp_ctx_t *ctx) | |
xmpp_free(ctx, buf); | ||
xmpp_stanza_release(stanza); | ||
|
||
/* create a string with two stanzas to make sure we don't | ||
* leak any memory when we convert them to a xmpp_stanza_t | ||
*/ | ||
buf = malloc(strlen(str) * 2 + 1); | ||
assert(buf != NULL); | ||
memcpy(buf, str, strlen(str) + 1); | ||
memcpy(&buf[strlen(str)], str, strlen(str) + 1); | ||
stanza = xmpp_stanza_new_from_string(ctx, buf); | ||
assert(stanza != NULL); | ||
free(buf); | ||
ret = xmpp_stanza_to_text(stanza, &buf, &buflen); | ||
assert(ret == XMPP_EOK); | ||
COMPARE(str, buf); | ||
xmpp_free(ctx, buf); | ||
xmpp_stanza_release(stanza); | ||
|
||
/* Error path. */ | ||
stanza = xmpp_stanza_new_from_string(ctx, "<uu><uu>tt"); | ||
assert(stanza == NULL); | ||
|