Break the linked-list of children before releasing a child.
Before this patch it was possible, when a child is cloned and stored
for longer than the lifetime of its parent, that its `next` pointer
points to invalid memory that was already free'd when the parent stanza
was released.
This issue exists already since the initial version of
`xmpp_stanza_release()`.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This patch handles the case where the server sends its list of features,
but the `<bind>` feature is missing.
A server doing so is violating RFC6120 (c.f. [0]), but it happened in [1].
Previously we ended up in a segfault, now we terminate the connection.
Reproducing this was done with netcat and profanity:
```
shell1 $ nc -l -p 5222
profanity $ /connect foo@127.0.0.1 tls disable
-> nc receives: '<?xml version="1.0"?><stream:stream to="127.0.0.1" xml:lang="en" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams">'
nc send: <?xml version="1.0"?>
<stream:stream from="127.0.0.1" id="foobarbaz" lang="en" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">
<features xmlns="http://etherx.jabber.org/streams"><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism></mechanisms></features>
-> nc receives: '<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">XXXXXXXXXX</auth>'
nc send: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
-> nc receives: '<?xml version="1.0"?><stream:stream to="127.0.0.1" xml:lang="en" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams"><stream:stream from="127.0.0.1" id="foobarbaz" lang="en" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">'
nc send: <?xml version="1.0"?>
<stream:stream from="127.0.0.1" id="foobarbaz" lang="en" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">
<features xmlns="http://etherx.jabber.org/streams"/>
-> pre-patch this lead to a segfault of profanity, now the stream gets closed.
```
[0] https://datatracker.ietf.org/doc/html/rfc6120#section-7.2
[1] https://github.com/profanity-im/profanity/issues/1849
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
libstrophe uses non-blocking sockets and the connect() syscall may
return before a TCP connection is established. This doesn't allow
to catch all possible errors synchronously and some of the errors
are handled in the event handler.
In a scenario with multiple SRV records and/or multiple IP addresses
resolution, we need to repeat connection attempt on a failure.
xmpp_sock_t resolves the above problem. It keeps resolved records and
addresses to repeat connect attempt asynchronously.
The resolver maybe returned an error code but allocated an RR list. Free
this list now in the resolver instead of depending on the user to free it
even though there was an error.
This API is only library internal, but still it makes more sense like that.
This issue was discovered in CI job [0].
[0] https://github.com/strophe/libstrophe/actions/runs/3874980845/jobs/6776501943
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
If functions `xmpp_conn_set_cafile()` or `xmpp_conn_set_capath()` are
called twice they leaked the previously allocated memory.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Instead of using the "cloning version" `xmpp_stanza_add_child()` use the
version that takes ownership, so we don't have to release directly
afterwards.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Instead of always releasing the stanza after calling `send_stanza()`, this
is done inside the function now.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
... and forgetting to 1. clear the password cache and 2. print a message
of what exactly happened ...
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Prevent assuming SM is enabled if the connection gets re-used without a
complete destroy&re-create of the connection object.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
When compiling on buildroot I get:
`src/tls.c:235:28: error: ‘ssize_t’ undeclared (first use in this
function); did you mean ‘size_t’? `
To have this POSIX type available we will need to include
`sys/types.h` or `unistd.h`.
Before this change the user had to provide a password callback, even if the
PKCS#12 encoded file has no or an empty password.
This changes the behavior, so we first try to open the file without a
password and only then ask the user to provide one.
This fixes#204.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
In order to be able to distinguish between user-created entries and
library-internal entries, we mark each entry who it belongs to.
This allows then later to let the user manage only the queue entries
that were created by them.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
The cache is stored per connection object and is cleared on
* entry of wrong password
* release of connection object
* successful connection
It can be configured that libstrophe retries the password entry in case
the user entered a wrong password.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
In order to be able to load password-protected key files a password
callback was added.
This also adds support for PKCS#12 containers instead of certificate+key.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
The registered callback function will be called before connect() is
called on the socket, allowing tweaking of much more than just keepalive
settings.
This deprecates xmpp_conn_set_keepalive().
Includes helper/example callback function to set default keepalive
parameters that some library users may find useful.
In order to do proper deprecation of those API's we re-introduce them
so they can be removed in the next release. This will then also lead to
an ABI bump.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
In case a pointer to itself was received, the resolver looped inifinitely
until the stack overflows.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
src/handler.c: In function 'handler_system_delete_all':
src/handler.c:706:25: warning: 'key2' may be used uninitialized in this function [-Wmaybe-uninitialized]
hash_add(conn->id_handlers, key2, head);
Instead of using the internal DRBG-based RNG, use the `getrandom()` system
call where available.
Keep the existing version as fall-back for other systems that don't provide
that system call.
... and for cases where auto-detection fails or the user simply wants to
use the internal RNG a new configure-switch is provided.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
... to provide an easier way to find long paths.
After looking at some code in profanity-im/profanity#1605 I thought this
could help to make libstrophe-user code easier to write (and read).
Initially it started off as `xmpp_stanza_get_child_by_xpath()` but then
I was annoyed when it came to handling all those potential corner cases
like e.g. escaping URL's in the ns ... so here we go with a
vararg approach :)
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
`hash_iter_next()` returns a pointer to an element of the data structure
which is persistent and not altered while calling `hash_iter_next()`.
Therefor we don't have to dup the string, but simply can remember the
pointer.
In the case where the element would be `hash_drop()`'ped which contains
the key, the key is not accessed after it has been free'd.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>