Merge pull request #2026 from profanity-im/debug-1994

Debug & fix #1994
This commit is contained in:
Michael Vetter
2025-03-21 15:59:07 +01:00
committed by GitHub
8 changed files with 68 additions and 51 deletions

View File

@@ -9435,17 +9435,16 @@ _url_aesgcm_method(ProfWin* window, const char* cmd_template, gchar* url, gchar*
auto_gchar gchar* filename = _prepare_filename(window, url, path);
if (!filename)
return;
auto_char char* id = get_random_string(4);
AESGCMDownload* download = malloc(sizeof(AESGCMDownload));
download->window = window;
AESGCMDownload* download = calloc(1, sizeof(AESGCMDownload));
download->id = get_random_string(4);
download->url = strdup(url);
download->filename = strdup(filename);
download->id = strdup(id);
if (cmd_template != NULL) {
download->cmd_template = strdup(cmd_template);
} else {
download->cmd_template = NULL;
}
download->window = window;
pthread_create(&(download->worker), NULL, &aesgcm_file_get, download);
aesgcm_download_add_download(download);
@@ -9458,38 +9457,38 @@ _download_install_plugin(ProfWin* window, gchar* url, gchar* path)
auto_gchar gchar* filename = _prepare_filename(window, url, path);
if (!filename)
return FALSE;
HTTPDownload* download = malloc(sizeof(HTTPDownload));
download->window = window;
HTTPDownload* download = calloc(1, sizeof(HTTPDownload));
download->id = get_random_string(4);
download->url = strdup(url);
download->filename = strdup(filename);
download->id = get_random_string(4);
download->cmd_template = NULL;
download->window = window;
download->silent = TRUE;
pthread_create(&(download->worker), NULL, &plugin_download_install, download);
plugin_download_add_download(download);
return TRUE;
}
void
static void
_url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* path)
{
auto_gchar gchar* filename = _prepare_filename(window, url, path);
if (!filename)
return;
auto_char char* id = get_random_string(4);
HTTPDownload* download = malloc(sizeof(HTTPDownload));
download->window = window;
HTTPDownload* download = calloc(1, sizeof(HTTPDownload));
download->id = get_random_string(4);
download->url = strdup(url);
download->filename = strdup(filename);
download->id = strdup(id);
download->cmd_template = cmd_template ? strdup(cmd_template) : NULL;
download->window = window;
download->silent = FALSE;
pthread_create(&(download->worker), NULL, &http_file_get, download);
http_download_add_download(download);
}
void
static void
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
{
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);

View File

@@ -49,16 +49,25 @@ int
omemo_crypto_init(void)
{
if (!gcry_check_version(GCRYPT_VERSION)) {
return -1;
return GPG_ERR_UNKNOWN_VERSION;
}
gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN);
gcry_error_t ret;
ret = gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN);
if (ret != 0)
return ret;
gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0);
ret = gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0);
if (ret != 0)
return ret;
gcry_control(GCRYCTL_RESUME_SECMEM_WARN);
ret = gcry_control(GCRYCTL_RESUME_SECMEM_WARN);
if (ret != 0)
return ret;
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
ret = gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
if (ret != 0)
return ret;
/* Ask for a first random buffer to ensure CSPRNG is initialized.
* Thus we control the memleak produced by gcrypt initialization and we can

View File

@@ -133,8 +133,9 @@ omemo_init(void)
prof_add_shutdown_routine(_omemo_close);
if (omemo_crypto_init() != 0) {
cons_show("Error initializing OMEMO crypto: gcry_check_version() failed");
gcry_error_t crypt_res = omemo_crypto_init();
if (crypt_res != 0) {
cons_show("Error initializing OMEMO crypto: %s", gcry_strerror(crypt_res));
}
pthread_mutexattr_init(&omemo_static_data.attr);

View File

@@ -77,7 +77,7 @@ aesgcm_file_get(void* userdata)
// Create a temporary file used for storing the ciphertext that is to be
// retrieved from the https:// URL.
auto_gchar char* tmpname = NULL;
auto_gchar gchar* tmpname = NULL;
auto_gfd gint tmpfd = 0;
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
@@ -101,7 +101,7 @@ aesgcm_file_get(void* userdata)
// We wrap the HTTPDownload tool and use it for retrieving the ciphertext
// and storing it in the temporary file previously opened.
HTTPDownload* http_dl = malloc(sizeof(HTTPDownload));
HTTPDownload* http_dl = calloc(1, sizeof(HTTPDownload));
http_dl->window = aesgcm_dl->window;
http_dl->worker = aesgcm_dl->worker;
http_dl->id = strdup(aesgcm_dl->id);
@@ -109,11 +109,17 @@ aesgcm_file_get(void* userdata)
http_dl->filename = strdup(tmpname);
http_dl->cmd_template = NULL;
http_dl->silent = FALSE;
http_dl->return_bytes_received = TRUE;
aesgcm_dl->http_dl = http_dl;
http_file_get(http_dl); // TODO(wstrm): Verify result.
ssize_t* p_bytes_received = http_file_get(http_dl);
if (!p_bytes_received) {
return NULL;
}
ssize_t bytes_received = *p_bytes_received;
free(p_bytes_received);
auto_FILE FILE* tmpfh = fopen(tmpname, "rb");
FILE* tmpfh = fopen(tmpname, "rb");
if (tmpfh == NULL) {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
"Downloading '%s' failed: Unable to open "
@@ -125,10 +131,9 @@ aesgcm_file_get(void* userdata)
gcry_error_t crypt_res;
crypt_res = omemo_decrypt_file(tmpfh, outfh,
http_dl->bytes_received, fragment);
bytes_received, fragment);
fclose(tmpfh);
remove(tmpname);
g_free(tmpname);
if (crypt_res != GPG_ERR_NO_ERROR) {
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,

View File

@@ -105,6 +105,7 @@ void*
http_file_get(void* userdata)
{
HTTPDownload* download = (HTTPDownload*)userdata;
ssize_t* ret = NULL;
char* err = NULL;
@@ -208,6 +209,10 @@ http_file_get(void* userdata)
"Downloading '%s': done\nSaved to '%s'",
download->url, download->filename);
win_mark_received(download->window, download->id);
if (download->return_bytes_received) {
ret = malloc(sizeof(*ret));
*ret = download->bytes_received;
}
}
}
@@ -236,12 +241,12 @@ out:
download_processes = g_slist_remove(download_processes, download);
pthread_mutex_unlock(&lock);
free(download->id);
free(download->url);
free(download->filename);
free(download->url);
free(download->id);
free(download);
return NULL;
return ret;
}
void

View File

@@ -58,6 +58,7 @@ typedef struct http_download_t
pthread_t worker;
int cancel;
gboolean silent;
gboolean return_bytes_received;
} HTTPDownload;
void* http_file_get(void* userdata);

View File

@@ -298,39 +298,36 @@ http_file_put(void* userdata)
pthread_mutex_lock(&lock);
if (err) {
gchar* msg;
auto_gchar gchar* err_msg = NULL;
if (upload->cancel) {
msg = g_strdup_printf("Uploading '%s' failed: Upload was canceled", upload->filename);
if (!msg) {
msg = g_strdup(FALLBACK_MSG);
err_msg = g_strdup_printf("Uploading '%s' failed: Upload was canceled", upload->filename);
if (!err_msg) {
err_msg = g_strdup(FALLBACK_MSG);
}
} else {
msg = g_strdup_printf("Uploading '%s' failed: %s", upload->filename, err);
if (!msg) {
msg = g_strdup(FALLBACK_MSG);
err_msg = g_strdup_printf("Uploading '%s' failed: %s", upload->filename, err);
if (!err_msg) {
err_msg = g_strdup(FALLBACK_MSG);
}
win_update_entry_message(upload->window, upload->put_url, msg);
win_update_entry_message(upload->window, upload->put_url, err_msg);
}
cons_show_error(msg);
g_free(msg);
cons_show_error(err_msg);
} else {
if (!upload->cancel) {
msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
if (!msg) {
msg = g_strdup(FALLBACK_MSG);
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
if (!status_msg) {
status_msg = g_strdup(FALLBACK_MSG);
}
win_update_entry_message(upload->window, upload->put_url, msg);
win_update_entry_message(upload->window, upload->put_url, status_msg);
win_mark_received(upload->window, upload->put_url);
g_free(msg);
char* url = NULL;
if (format_alt_url(upload->get_url, upload->alt_scheme, upload->alt_fragment, &url) != 0) {
gchar* msg = g_strdup_printf("Uploading '%s' failed: Bad URL ('%s')", upload->filename, upload->get_url);
if (!msg) {
msg = g_strdup(FALLBACK_MSG);
auto_gchar gchar* fail_msg = g_strdup_printf("Uploading '%s' failed: Bad URL ('%s')", upload->filename, upload->get_url);
if (!fail_msg) {
fail_msg = g_strdup(FALLBACK_MSG);
}
cons_show_error(msg);
g_free(msg);
cons_show_error(fail_msg);
} else {
switch (upload->window->type) {
case WIN_CHAT:

View File

@@ -62,9 +62,9 @@ plugin_download_install(void* userdata)
{
HTTPDownload* plugin_dl = (HTTPDownload*)userdata;
/* We need to dup those, because they're free'd inside `http_file_get()` */
auto_char char* path = strdup(plugin_dl->filename);
auto_char char* https_url = strdup(plugin_dl->url);
plugin_dl->silent = TRUE;
http_file_get(plugin_dl);