Commit Graph

5448 Commits

Author SHA1 Message Date
Michael Vetter
5385cc28be Add note about xep0454 to /sendfile
Fix https://github.com/profanity-im/profanity/issues/2040
2025-04-22 15:07:33 +02:00
Steffen Jaeckel
ed44d7ad96 Fix handling of roster pushes
We must only return early in cases where we received a roster push with
1. a `from` attribute
2. that `from` is not our bare JID

The server sends roster pushes without `from` attribute and we must accept
them.

Fixes #2035
Fixes: bac24601da ("Introduce `equals_our_barejid()`")

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-11 18:55:17 +02:00
Steffen Jaeckel
5efec675fd No need to always get a fresh list of keys or values.
> The returned data is valid until changes to the hash release those keys.
As of the doc of `g_hash_table_get_keys()` [0].

> The returned data is valid until hash_table is modified.
As of the doc of `g_hash_table_get_values()` [1].

Use this property and create the lists when modifying the hashtable.
The `keys` list is most of the time used sorted, so sort it immediately. In
the cases where it was not used sorted, it does not matter.

This started off by looking into whether this can be improved.
`g_hash_table_foreach()` is discouraged to be used and proposes to use
a `GHashTableIter`. Since our lists are not modified very often it does not
really make sense, so I decided to keep using lists, but allocating
those lists statically instead of per invocation.

Instead of using a list, we could maybe use the `GArray` version, but
I am not sure whether it wouldn't be even better to replace the
`GHashTable` all along to store the `windows` instead.

[0] https://docs.gtk.org/glib/type_func.HashTable.get_keys.html
[1] https://docs.gtk.org/glib/type_func.HashTable.get_values.html

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-11 18:55:17 +02:00
Steffen Jaeckel
a6f1250589 Fix memleak
`end_date` only gets free'd if `chatwin_db_history()` is called, which is
not always the case.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-02 13:07:47 +02:00
Steffen Jaeckel
3bf72210e1 Add iso8601 when setting a time format
Instead of manually typing the format-string, one can now simply use
`iso8601`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-02 13:07:47 +02:00
Steffen Jaeckel
9c2b3f6579 Re-factor cmd_time()
Instead of c&p'ing the same code again and again, put everything in a
struct and loop over it.

This also fixes `vcard` not being in included in `all`.

Fixes: f934c5b59f ("Add vCard support")

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-02 13:07:47 +02:00
Steffen Jaeckel
1e764ab76d More const correctness
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-04-02 13:07:35 +02:00
Michael Vetter
07dfeec816 Release 0.15.0 2025-03-27 20:06:38 +01:00
Steffen Jaeckel
6d3f20fe8e Close FILE* before removing the filename.
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-18 17:00:58 +01:00
Steffen Jaeckel
4405f33884 Optionally return bytes received from http_file_get()
`http_dl->bytes_received` was already free'd when it was accessed inside
`aesgcm_file_get()`.

Change `http_file_get()` to optionally return the number of bytes received
so we know how much data we have to decrypt.

This fixes #1994

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-18 17:00:58 +01:00
Steffen Jaeckel
422f5fa6f9 Slightly improve http_download related allocations.
* use `calloc()` to allocate zero-initialized structs.
* order the allocation of members by their declaration.
* order the freeing of members in reverse order.
* move init of `silent` flag in plugin case.
* fix double free of `tmpname` in `aesgcm_file_get()`.
* make some functions static.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-18 17:00:58 +01:00
Steffen Jaeckel
cffd310744 Fix shadowing of msg resulting in invalid free.
```
==500714== Invalid free() / delete / delete[] / realloc()
==500714==    at 0x484A78B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==500714==    by 0x5BDCD58: g_free (in /usr/lib64/libglib-2.0.so.0.8200.2)
==500714==    by 0x49016B: http_file_put (http_upload.c:175)
==500714==    by 0x5F613B1: start_thread (in /usr/lib64/libc.so.6)
==500714==    by 0x5FE63D3: clone (in /usr/lib64/libc.so.6)
==500714==  Address 0x86f6510 is 0 bytes inside a block of size 53 free'd
==500714==    at 0x484A78B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==500714==    by 0x5BDCD58: g_free (in /usr/lib64/libglib-2.0.so.0.8200.2)
==500714==    by 0x490299: http_file_put (http_upload.c:324)
==500714==    by 0x5F613B1: start_thread (in /usr/lib64/libc.so.6)
==500714==    by 0x5FE63D3: clone (in /usr/lib64/libc.so.6)
==500714==  Block was alloc'd at
==500714==    at 0x48477C4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==500714==    by 0x5F548A7: __vasprintf_internal (in /usr/lib64/libc.so.6)
==500714==    by 0x5C2DD1D: g_vasprintf (in /usr/lib64/libglib-2.0.so.0.8200.2)
==500714==    by 0x5BF8D97: g_strdup_vprintf (in /usr/lib64/libglib-2.0.so.0.8200.2)
==500714==    by 0x5BF8E58: g_strdup_printf (in /usr/lib64/libglib-2.0.so.0.8200.2)
==500714==    by 0x490264: http_file_put (http_upload.c:318)
==500714==    by 0x5F613B1: start_thread (in /usr/lib64/libc.so.6)
==500714==    by 0x5FE63D3: clone (in /usr/lib64/libc.so.6)
```

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-18 17:00:58 +01:00
Steffen Jaeckel
59aa9d64df Check return values of libgcrypt initialisation.
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-17 17:00:17 +01:00
Steffen Jaeckel
25184a53e0 Improve const correctness.
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-13 15:07:39 +01:00
Steffen Jaeckel
666895905b Revert API change of plugins_pre_chat_message_display()
In order to keep the C plugins API stable, we have to revert this part of
the changes done in 16ed7cc187.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-13 13:28:06 +01:00
Steffen Jaeckel
a9c601101d Simplify code
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-13 13:02:13 +01:00
Steffen Jaeckel
4940218257 Minimize strdup() operations in plugins.
Instead of dup'ing each string before free'ing it, simply re-use the same.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-13 13:01:36 +01:00
Michael Vetter
5b9516b483 Merge pull request #2022 from profanity-im/fixes
Memory fixes
2025-03-13 09:58:09 +01:00
Michael Vetter
71b7d97dcb Get rid of unused define 2025-03-13 09:48:32 +01:00
Michael Vetter
b5f0cc0bd4 Fix more potential leaks in aesgcm_download 2025-03-13 09:48:27 +01:00
Steffen Jaeckel
edb41bef60 Re-factor notifier.
* Add an internal `_notifier_uninit()` function.
* Instead of `#ifdef` inside `notify()`, provide different target-specific
static implementations.

This also introduces `log_error_once()`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-12 10:15:39 +01:00
Steffen Jaeckel
83a4165d92 plugins_(on|pre) API now maybe returns NULL.
Instead of always returning a `strdup()`'ed version, maybe return NULL and
handle this in the calling code.

This is still not true for `plugins_pre_chat_message_display()`, where we
return the passed `messag` in case there are no plugins, since this would
require a bigger refactor of more parts.

This also
* merges the implementation of `sv_ev_incoming_private_message()` and
  `sv_ev_delayed_private_message()`, since they differed only by a single
  line.
* untangles the `#ifdef` mess in `cl_ev_send_muc_msg_corrected()`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-12 10:15:35 +01:00
Steffen Jaeckel
95c2199ca2 Some more memory improvements
* Less leaks
* Less allocations

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-12 10:09:41 +01:00
Steffen Jaeckel
9fc0326428 Add Valgrind to CI
* Also pass `$*` to `configure` when invoking `ci-build.sh`, so one can
  e.g. run `./ci-build.sh --without-xscreensaver`

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-11 12:15:09 +01:00
Steffen Jaeckel
c0da36c48d Rage-cleanup.
While trying to get the unit tests working again I stumbled over all those
things that I thought could be better^TM.

Now we also know "TODO: why does this make the test fail?" - because
the unit tests are brittle AF ... and we have to init the subsystems
we use in the test, otherwise the cleanup will fail...

BTW. you can now also only run a single test ... or a pattern or so ...
you'd have to read how `cmocka_set_test_filter()` works exactly.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-10 11:45:15 +01:00
Steffen Jaeckel
72b99ceb6d Some minor improvements
* destroy/free/shutdown/close in reverse order of allocation
* more static/auto_Xfree
* less variables/strlen/GString
* properly `\0`-terminate string of testcase

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-10 11:45:15 +01:00
Steffen Jaeckel
b55bf6e4bd Fix some more memory leaks + an invalid read.
`ProfMessage` was not completely initialized, fix this by using `calloc()`
for the allocation.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-10 11:45:15 +01:00
Steffen Jaeckel
c5a131ee46 Introduce our own shutdown callback mechanism.
Instead of adding stuff to `_shutdown()`, we can now register a shutdown
routine from the respective `init()` function of our modules.

This also has the advantage, that we're sure they're called in reverse
order from how the initialization happened.

I didn't simply use `atexit()` because POSIX says that the number of
possible callbacks is limited (min 32) and I was not sure whether
we will maybe extend this number at one point.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-07 21:09:16 +01:00
Steffen Jaeckel
662a0be633 Add --cmd option
This allows to kind of automate what profanity should do as first jobs,
e.g. `--cmd /foo --cmd /bar --cmd /quit` so one can easily check for memory
leaks.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-03-07 21:09:16 +01:00
Michael Vetter
43bbb16e8e Close file in case of error 2025-03-06 11:19:28 +01:00
Michael Vetter
55a8a26a24 Attempt to open file later to prevent potential resource leak 2025-03-06 11:19:00 +01:00
Michael Vetter
0081db643f Merge pull request #2015 from ventosus/issue#2012
Load resources from chat history db
2025-01-28 17:25:10 +01:00
Steffen Jaeckel
f27fa98717 Some minor changes
* Fix some linter suggestions.
* Change some defines to `const` vars.
* Free buffer entries in the reverse order they were allocated.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
8151dfa3b4 /quit now exits from the event loop
Before this change issuing `/quit` directly called `exit(0)` and did not
invoke all the graceful shutdown routines. Now we first try to exit from
the event loop, which includes cleaning up everything.
In case the event loop is stuck for some reason, you could try to issue a
second `/quit`, which will then directly call `exit(0)`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
2696989ce5 Fix a bunch of obvious memory leaks at termination
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
06f5c2670e PyEval_InitThreads() is deprecated
`Py_Initialize()` does it since 3.7, it's a noop and deprecated since 3.9.

https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
80193ca41f cmd_ac: Refactor alloc, reset & free
Add all elements to an array, in order to easily be able to run operations
in bulk.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
46b788846c These defines don't have to be in the header file
They're only used in `window.c`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2025-01-28 16:43:13 +01:00
Steffen Jaeckel
67d8d7110b Revert "Fix underscrolling problem"
This reverts commit d7e46d64fe.
2025-01-28 16:43:13 +01:00
Hanspeter Portner
c804137669 Load resources from chat history db
Fixes: https://github.com/profanity-im/profanity/issues/2012
2025-01-26 20:12:41 +01:00
Hanspeter Portner
cb395b7c09 Make muc_nick return a const char* const
In the documentation of the `muc_nick` function we can read:

> The nickname is owned by the chat room and should not be modified or freed

We should reflect that in the return type and `strdup` the value for the
plugin API.

Fixes: https://github.com/profanity-im/profanity/issues/2013
2025-01-26 18:16:14 +01:00
Martin Dosch
50e82376b0 Remove plenking
There were two cases of plenking (a space between a word and the punctuation
marks) in front of `…`.
2024-10-03 15:51:52 +02:00
Michael Vetter
69301503ce Add missing space to description 2024-09-19 08:34:21 +02:00
Michael Vetter
0995b1a180 Add NULL check to _gpgme_key_to_ProfPGPKey
Fix https://github.com/profanity-im/profanity/issues/1995

Tested-by: Martin Dosch <martin@mdosch.de>
2024-09-07 12:44:42 +02:00
Michael Vetter
996a1fdf35 Fix build on some compilers regardind switch statement
Fix the famous `error: a label can only be part of a statement and a
declaration is not a statement`.
2024-06-20 18:04:12 +02:00
Michael Vetter
f147a5ca27 Change default download location
`/url save $someurl` will now download to
`~/.local/share/profanity/downloads/from_jid/date/filename` instead of
`~/.local/share/profanity/downloads`.

Like this the downloaded files should be better ordered.

This will only happen for MUC and 1:1 chat windows.
Private windows might have only a nick or jid. Lets not distinguish
between those two ways. And since the nick option is unreliable to be
the same person lets just put them in the general downloads folder.
As is done with downloads from all other windows as well.

I also had the idea to make this configurable but this suits my needs
and time limits right now.
2024-06-20 13:35:14 +02:00
Michael Vetter
29fd8199f1 Merge pull request #1978 from profanity-im/feat/1974-actlist
Make statusbar actlist respect the /statusbar show setting
2024-06-20 12:47:34 +02:00
Michael Vetter
534c14917a Merge pull request #1982 from profanity-im/fix/1976-autocon-acc
Reset autoconnect account when the account gets removed
2024-06-20 12:45:53 +02:00
Michael Vetter
07900e9617 Revert "Fix potential double free of ratchet identity key"
This reverts commit 3b099e9403.

This resulted in:
```
==5285== Invalid read of size 16
==5285==    at 0x4FA80FC: ec_public_key_serialize (in /usr/lib64/libsignal-protocol-c.so.2.3.3)
==5285==    by 0x4E5E76: omemo_identity_key (omemo.c:419)
==5285==    by 0x4EBB7E: omemo_bundle_publish (omemo.c:129)
==5285==    by 0x4E5BD9: omemo_publish_crypto_materials (omemo.c:335)
==5285==    by 0x460407: sv_ev_connection_features_received (server_events.c:202)
==5285==    by 0x43AA87: connection_features_received (connection.c:779)
==5285==    by 0x4418C9: _disco_info_response_id_handler_onconnect (iq.c:2423)
==5285==    by 0x43B9F1: _iq_handler (iq.c:241)
==5285==    by 0x5163848: ??? (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x516A224: ??? (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x5E4FE43: ??? (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5E54927: xmlParseChunk (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5163450: xmpp_run_once (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x439797: connection_check_events (connection.c:162)
==5285==    by 0x43894E: session_process_events (session.c:256)
==5285==    by 0x4319FF: prof_run (profanity.c:128)
==5285==    by 0x4EDAE6: main (main.c:174)
==5285==  Address 0xa1cb1e0 is 16 bytes inside a block of size 72 free'd
==5285==    at 0x484875B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==5285==    by 0x4395D0: _xfree (connection.c:110)
==5285==    by 0x516A1A7: xmpp_stanza_release (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x516A16C: xmpp_stanza_release (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x516A16C: xmpp_stanza_release (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x516A230: ??? (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x5E4FE43: ??? (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5E54927: xmlParseChunk (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5163450: xmpp_run_once (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x439797: connection_check_events (connection.c:162)
==5285==    by 0x43894E: session_process_events (session.c:256)
==5285==    by 0x4319FF: prof_run (profanity.c:128)
==5285==    by 0x4EDAE6: main (main.c:174)
==5285==  Block was alloc'd at
==5285==    at 0x4845794: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==5285==    by 0x43958A: _xmalloc (connection.c:102)
==5285==    by 0x516A0D1: xmpp_stanza_new (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x516BF34: ??? (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x5F10A17: ??? (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5E5481F: xmlParseChunk (in /usr/lib64/libxml2.so.2.12.8)
==5285==    by 0x5163450: xmpp_run_once (in /usr/lib64/libstrophe.so.0.13.1)
==5285==    by 0x439797: connection_check_events (connection.c:162)
==5285==    by 0x43894E: session_process_events (session.c:256)
==5285==    by 0x4319FF: prof_run (profanity.c:128)
==5285==    by 0x4EDAE6: main (main.c:174)
```

Tested via sending OMEMO messages via 1:1 and in MUC.
2024-06-20 12:41:20 +02:00
Michael Vetter
5765edbe1b Reset autoconnect account when the account gets removed
When a user added an account, set it as autoconnect and then removed
that account. It still was set as the autoconnect account.

```
    /account add test
    /autoconnect set test
    /account remove test
    /save
    /quit
    Start profanity
```

Fix https://github.com/profanity-im/profanity/issues/1976
2024-06-20 11:04:20 +02:00