mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-08-01 23:36:21 +00:00
Fix more potential leaks in aesgcm_download
This commit is contained in:
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -31,10 +31,10 @@ jobs:
|
|||||||
# if this check fails, you have to update the number of auto types known and the list of auto types in the check below
|
# if this check fails, you have to update the number of auto types known and the list of auto types in the check below
|
||||||
- name: Check auto types are up-to-date
|
- name: Check auto types are up-to-date
|
||||||
run: |
|
run: |
|
||||||
[[ "$(find src -type f -name '*.[ch]' -exec awk '/^#define auto_[\W]*/ {print $2}' '{}' \; | sort -u | wc -l)" == "6" ]] || exit -1
|
[[ "$(find src -type f -name '*.[ch]' -exec awk '/^#define auto_[\W]*/ {print $2}' '{}' \; | sort -u | wc -l)" == "8" ]] || exit -1
|
||||||
- name: Check auto types are initialized
|
- name: Check auto types are initialized
|
||||||
run: |
|
run: |
|
||||||
grep -P 'auto_(char|gchar|gcharv|guchar|jid|sqlite)[\w *]*;$' -r src && exit -1 || true
|
grep -P 'auto_(char|gchar|gcharv|guchar|jid|sqlite|gfd|FILE)[\w *]*;$' -r src && exit -1 || true
|
||||||
- name: Run clang-format
|
- name: Run clang-format
|
||||||
uses: jidicula/clang-format-action@v4.11.0
|
uses: jidicula/clang-format-action@v4.11.0
|
||||||
with:
|
with:
|
||||||
|
|||||||
30
src/common.c
30
src/common.c
@@ -130,6 +130,36 @@ auto_free_char(char** str)
|
|||||||
free(*str);
|
free(*str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the file descriptor.
|
||||||
|
*
|
||||||
|
* @param fd file descriptor handle. If NULL, no action is taken.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
auto_close_gfd(gint* fd)
|
||||||
|
{
|
||||||
|
if (fd == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (close(*fd) == EOF)
|
||||||
|
log_error(g_strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes file stream
|
||||||
|
*
|
||||||
|
* @param fd file descriptor handle opened with fopen. If NULL, no action is taken.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
auto_close_FILE(FILE** fd)
|
||||||
|
{
|
||||||
|
if (fd == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fclose(*fd) == EOF)
|
||||||
|
log_error(g_strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_load_keyfile(prof_keyfile_t* keyfile)
|
_load_keyfile(prof_keyfile_t* keyfile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,6 +104,14 @@ void auto_free_guchar(guchar** str);
|
|||||||
*/
|
*/
|
||||||
#define auto_guchar __attribute__((__cleanup__(auto_free_guchar)))
|
#define auto_guchar __attribute__((__cleanup__(auto_free_guchar)))
|
||||||
|
|
||||||
|
#define auto_gfd __attribute__((__cleanup__(auto_close_gfd)))
|
||||||
|
|
||||||
|
void auto_close_gfd(gint* fd);
|
||||||
|
|
||||||
|
#define auto_FILE __attribute__((__cleanup__(auto_close_FILE)))
|
||||||
|
|
||||||
|
void auto_close_FILE(FILE** fd);
|
||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
#define STR_MAYBE_NULL(p) (p) ?: "(null)"
|
#define STR_MAYBE_NULL(p) (p) ?: "(null)"
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ aesgcm_file_get(void* userdata)
|
|||||||
{
|
{
|
||||||
AESGCMDownload* aesgcm_dl = (AESGCMDownload*)userdata;
|
AESGCMDownload* aesgcm_dl = (AESGCMDownload*)userdata;
|
||||||
|
|
||||||
char* https_url = NULL;
|
auto_char char* https_url = NULL;
|
||||||
char* fragment = NULL;
|
auto_char char* fragment = NULL;
|
||||||
|
|
||||||
// Convert the aesgcm:// URL to a https:// URL and extract the encoded key
|
// Convert the aesgcm:// URL to a https:// URL and extract the encoded key
|
||||||
// and tag stored in the URL fragment.
|
// and tag stored in the URL fragment.
|
||||||
@@ -79,8 +79,8 @@ aesgcm_file_get(void* userdata)
|
|||||||
|
|
||||||
// Create a temporary file used for storing the ciphertext that is to be
|
// Create a temporary file used for storing the ciphertext that is to be
|
||||||
// retrieved from the https:// URL.
|
// retrieved from the https:// URL.
|
||||||
gchar* tmpname = NULL;
|
auto_gchar char* tmpname = NULL;
|
||||||
gint tmpfd;
|
auto_gfd gint tmpfd = 0;
|
||||||
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
|
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
"Downloading '%s' failed: Unable to create "
|
"Downloading '%s' failed: Unable to create "
|
||||||
@@ -91,7 +91,7 @@ aesgcm_file_get(void* userdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the target file for storing the cleartext.
|
// Open the target file for storing the cleartext.
|
||||||
FILE* outfh = fopen(aesgcm_dl->filename, "wb");
|
auto_FILE FILE* outfh = fopen(aesgcm_dl->filename, "wb");
|
||||||
if (outfh == NULL) {
|
if (outfh == NULL) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
"Downloading '%s' failed: Unable to open "
|
"Downloading '%s' failed: Unable to open "
|
||||||
@@ -115,16 +115,13 @@ aesgcm_file_get(void* userdata)
|
|||||||
|
|
||||||
http_file_get(http_dl); // TODO(wstrm): Verify result.
|
http_file_get(http_dl); // TODO(wstrm): Verify result.
|
||||||
|
|
||||||
FILE* tmpfh = fopen(tmpname, "rb");
|
auto_FILE FILE* tmpfh = fopen(tmpname, "rb");
|
||||||
if (tmpfh == NULL) {
|
if (tmpfh == NULL) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
"Downloading '%s' failed: Unable to open "
|
"Downloading '%s' failed: Unable to open "
|
||||||
"temporary file at '%s' for reading (%s).",
|
"temporary file at '%s' for reading (%s).",
|
||||||
aesgcm_dl->url, tmpname,
|
aesgcm_dl->url, tmpname,
|
||||||
g_strerror(errno));
|
g_strerror(errno));
|
||||||
if (fclose(outfh) == EOF) {
|
|
||||||
cons_show_error(g_strerror(errno));
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,11 +129,6 @@ aesgcm_file_get(void* userdata)
|
|||||||
crypt_res = omemo_decrypt_file(tmpfh, outfh,
|
crypt_res = omemo_decrypt_file(tmpfh, outfh,
|
||||||
http_dl->bytes_received, fragment);
|
http_dl->bytes_received, fragment);
|
||||||
|
|
||||||
if (fclose(tmpfh) == EOF) {
|
|
||||||
cons_show_error(g_strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
close(tmpfd);
|
|
||||||
remove(tmpname);
|
remove(tmpname);
|
||||||
g_free(tmpname);
|
g_free(tmpname);
|
||||||
|
|
||||||
@@ -147,13 +139,6 @@ aesgcm_file_get(void* userdata)
|
|||||||
https_url, gcry_strerror(crypt_res));
|
https_url, gcry_strerror(crypt_res));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(outfh) == EOF) {
|
|
||||||
cons_show_error(g_strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
free(https_url);
|
|
||||||
free(fragment);
|
|
||||||
|
|
||||||
if (aesgcm_dl->cmd_template != NULL) {
|
if (aesgcm_dl->cmd_template != NULL) {
|
||||||
gchar** argv = format_call_external_argv(aesgcm_dl->cmd_template,
|
gchar** argv = format_call_external_argv(aesgcm_dl->cmd_template,
|
||||||
aesgcm_dl->filename,
|
aesgcm_dl->filename,
|
||||||
|
|||||||
Reference in New Issue
Block a user