From 9b7baee3e1b7ef3ebcfd876948fb26b5697927e3 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 07:33:54 +0300 Subject: [PATCH 01/16] Guess update information based on GitHub Actions environment variables Reads the GITHUB_REPOSITORY and GITHUB_REF environment variables and attempts to generate an appropriate updateinformation Adapted from https://github.com/probonopd/go-appimage/blob/7fab45552eb485c0076fd310835fa7958f981de0/src/appimagetool/appimagetool.go\#L547-L567 --- src/appimagetool.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/appimagetool.c b/src/appimagetool.c index 2d5a4ab04..1c2c26b6d 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -502,6 +502,14 @@ main (int argc, char *argv[]) char* github_token; github_token = getenv("GITHUB_TOKEN"); + /* Parse GitHub CI environment variables. + * https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables + */ + char* GITHUB_REPOSITORY; + GITHUB_REPOSITORY = getenv("GITHUB_REPOSITORY"); + char* GITHUB_REF; + GITHUB_REF = getenv("GITHUB_REF"); + /* Parse GitLab CI environment variables. * https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables * echo "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME}" @@ -903,6 +911,28 @@ main (int argc, char *argv[]) printf("Will not guess update information since zsyncmake is missing\n"); } } + } else if(GITHUB_REPOSITORY){ + gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); + if (zsyncmake_path){ + char buf[1024]; + printf("Running on GitHub Actions\n"); + if (strstr(GITHUB_REF, "/pull/")) { + printf("Will not calculate update information for GitHub because this is a pull request\n"); + } else { + gchar **parts = g_strsplit (GITHUB_REPOSITORY, "/", 0); + + char* channel; + if (GITHUB_REF != "" && strstr(GITHUB_REF, "/continuous/")) { + channel = "latest"; + } else { + channel = "continuous"; + } + sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + updateinformation = buf; + printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", GITHUB_REPOSITORY, GITHUB_REF); + printf("%s\n", updateinformation); + } + } } else if(CI_COMMIT_REF_NAME){ // ${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME} gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); From 98079b9ee8ba8b46f90ff019620dfe2f3458b0dc Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 14:32:56 +0300 Subject: [PATCH 02/16] style: use lower case (snake_case) for variable names --- src/appimagetool.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 1c2c26b6d..b618adb0e 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -505,10 +505,8 @@ main (int argc, char *argv[]) /* Parse GitHub CI environment variables. * https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables */ - char* GITHUB_REPOSITORY; - GITHUB_REPOSITORY = getenv("GITHUB_REPOSITORY"); - char* GITHUB_REF; - GITHUB_REF = getenv("GITHUB_REF"); + char* github_repository = getenv("GITHUB_REPOSITORY"); + char* github_ref = getenv("GITHUB_REF"); /* Parse GitLab CI environment variables. * https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables @@ -911,25 +909,25 @@ main (int argc, char *argv[]) printf("Will not guess update information since zsyncmake is missing\n"); } } - } else if(GITHUB_REPOSITORY){ + } else if(github_repository){ gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); if (zsyncmake_path){ char buf[1024]; printf("Running on GitHub Actions\n"); - if (strstr(GITHUB_REF, "/pull/")) { + if (strstr(github_ref, "/pull/")) { printf("Will not calculate update information for GitHub because this is a pull request\n"); } else { - gchar **parts = g_strsplit (GITHUB_REPOSITORY, "/", 0); + gchar **parts = g_strsplit (github_repository, "/", 0); char* channel; - if (GITHUB_REF != "" && strstr(GITHUB_REF, "/continuous/")) { + if (github_ref != "" && strstr(github_ref, "/continuous/")) { channel = "latest"; } else { channel = "continuous"; } sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); updateinformation = buf; - printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", GITHUB_REPOSITORY, GITHUB_REF); + printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); printf("%s\n", updateinformation); } } From 62be000b14480a5199d304f5ceda68f9205dd818 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 15:52:36 +0300 Subject: [PATCH 03/16] docs: Move travis CI specific documentation Move travis_ci specific documentation to travis_repo_slug `if` block --- src/appimagetool.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index b618adb0e..bf285b929 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -875,11 +875,10 @@ main (int argc, char *argv[]) printf("%s\n", updateinformation); } } - - /* If the user has not provided update information but we know this is a Travis CI build, - * then fill in update information based on TRAVIS_REPO_SLUG */ if(guess_update_information){ if(travis_repo_slug){ + /* If the user has not provided update information but we know this is a Travis CI build, + * then fill in update information based on TRAVIS_REPO_SLUG */ if(!github_token) { printf("Will not guess update information since $GITHUB_TOKEN is missing,\n"); if(0 != strcmp(travis_pull_request, "false")){ From fafcd4192df1f809f709f1fe4129a9ce1b97becb Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 15:53:32 +0300 Subject: [PATCH 04/16] fix: Check if github_repository and github_ref variables are not NULL --- src/appimagetool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index bf285b929..4157209eb 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -908,7 +908,6 @@ main (int argc, char *argv[]) printf("Will not guess update information since zsyncmake is missing\n"); } } - } else if(github_repository){ gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); if (zsyncmake_path){ char buf[1024]; @@ -930,6 +929,7 @@ main (int argc, char *argv[]) printf("%s\n", updateinformation); } } + } else if (github_repository != NULL && github_ref != NULL) { } else if(CI_COMMIT_REF_NAME){ // ${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME} gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); From 628d17118387d2f9654a032789df3cc546767e65 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 15:55:24 +0300 Subject: [PATCH 05/16] style: Fix github_actions if code suite indentation --- src/appimagetool.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 4157209eb..3f124f7a6 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -908,28 +908,26 @@ main (int argc, char *argv[]) printf("Will not guess update information since zsyncmake is missing\n"); } } - gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); - if (zsyncmake_path){ - char buf[1024]; - printf("Running on GitHub Actions\n"); - if (strstr(github_ref, "/pull/")) { - printf("Will not calculate update information for GitHub because this is a pull request\n"); - } else { - gchar **parts = g_strsplit (github_repository, "/", 0); - - char* channel; - if (github_ref != "" && strstr(github_ref, "/continuous/")) { - channel = "latest"; - } else { - channel = "continuous"; - } sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); - updateinformation = buf; - printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); - printf("%s\n", updateinformation); - } - } } else if (github_repository != NULL && github_ref != NULL) { + printf("Running on GitHub Actions\n"); + gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); + if (zsyncmake_path) { + if (strstr(github_ref, "/pull/")) { + printf("Will not calculate update information for GitHub because this is a pull request\n"); + } else { + printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); + char buf[1024]; + gchar **parts = g_strsplit (github_repository, "/", 2); + char* channel; + if (github_ref != "" && strstr(github_ref, "/continuous/")) { + channel = "latest"; + } else { + channel = "continuous"; + } + updateinformation = buf; + printf("%s\n", updateinformation); + } } else if(CI_COMMIT_REF_NAME){ // ${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME} gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); From c9b1a2682b2d349d33f373562b49c943d26249c6 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 15:58:33 +0300 Subject: [PATCH 06/16] feat: Use snprintf instead of sprintf to avoid potential buffer overflow https://github.com/AppImage/AppImageKit/pull/1075#discussion_r486160069 --- src/appimagetool.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 3f124f7a6..904550ecf 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -908,7 +908,6 @@ main (int argc, char *argv[]) printf("Will not guess update information since zsyncmake is missing\n"); } } - sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); } else if (github_repository != NULL && github_ref != NULL) { printf("Running on GitHub Actions\n"); gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); @@ -925,6 +924,11 @@ main (int argc, char *argv[]) } else { channel = "continuous"; } + int is_zsync_write_success = snprintf(buf, 1024, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + if (is_zsync_write_success < 0) { + printf("Writing updateinformation failed. zsync information is too long. (> 1024)\n"); + exit(is_zsync_write_success); + } updateinformation = buf; printf("%s\n", updateinformation); } From 4e7307ae7c1364c838abcb666798db1a5a648ceb Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Thu, 10 Sep 2020 15:59:26 +0300 Subject: [PATCH 07/16] fix: add an else block to inform the user of missing zsyncmake in github_actions --- src/appimagetool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/appimagetool.c b/src/appimagetool.c index 904550ecf..70114af53 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -932,6 +932,9 @@ main (int argc, char *argv[]) updateinformation = buf; printf("%s\n", updateinformation); } + } else { + printf("Will not guess update information since zsyncmake is missing\n"); + } } else if(CI_COMMIT_REF_NAME){ // ${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME} gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); From fe6f97b4de5373444d2c15e3792e1569061d3210 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 14:52:20 +0300 Subject: [PATCH 08/16] fix: define a constant buffer_size = 1024 and reuse it in setting updateinformation max size --- src/appimagetool.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 70114af53..2ee6344fd 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -825,7 +825,10 @@ main (int argc, char *argv[]) * should hopefully change that. */ fprintf (stderr, "Generating squashfs...\n"); + const int buffer_size = 1024; int size = 0; + + char* data = NULL; bool using_external_data = false; if (runtime_file != NULL) { @@ -866,10 +869,11 @@ main (int argc, char *argv[]) printf("Could not set executable bit, aborting\n"); exit(1); } - + + if(bintray_user != NULL){ if(bintray_repo != NULL){ - char buf[1024]; + char buf[buffer_size]; sprintf(buf, "bintray-zsync|%s|%s|%s|%s-_latestVersion-%s.AppImage.zsync", bintray_user, bintray_repo, app_name_for_filename, app_name_for_filename, arch); updateinformation = buf; printf("%s\n", updateinformation); @@ -924,7 +928,7 @@ main (int argc, char *argv[]) } else { channel = "continuous"; } - int is_zsync_write_success = snprintf(buf, 1024, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + int is_zsync_write_success = snprintf(buf, buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { printf("Writing updateinformation failed. zsync information is too long. (> 1024)\n"); exit(is_zsync_write_success); From 42b20c2bf7fd440eda20f836992e8860b12d96dd Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 15:37:13 +0300 Subject: [PATCH 09/16] fix: use strcmp for empty string check --- src/appimagetool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 2ee6344fd..b15c2e277 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -923,14 +923,14 @@ main (int argc, char *argv[]) char buf[1024]; gchar **parts = g_strsplit (github_repository, "/", 2); char* channel; - if (github_ref != "" && strstr(github_ref, "/continuous/")) { + if (strcmp(github_ref, "") != 0 && strstr(github_ref, "/continuous/")) { channel = "latest"; } else { channel = "continuous"; } int is_zsync_write_success = snprintf(buf, buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { - printf("Writing updateinformation failed. zsync information is too long. (> 1024)\n"); + printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", buffer_size); exit(is_zsync_write_success); } updateinformation = buf; From 3e39d09935e217eedc03c9d1aed6080e55f72d62 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 16:03:08 +0300 Subject: [PATCH 10/16] fix: explicitly check if return of strstr is NULL pointer --- src/appimagetool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index b15c2e277..985364df5 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -916,14 +916,14 @@ main (int argc, char *argv[]) printf("Running on GitHub Actions\n"); gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); if (zsyncmake_path) { - if (strstr(github_ref, "/pull/")) { + if (strstr(github_ref, "/pull/") != NULL) { printf("Will not calculate update information for GitHub because this is a pull request\n"); } else { printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); char buf[1024]; gchar **parts = g_strsplit (github_repository, "/", 2); char* channel; - if (strcmp(github_ref, "") != 0 && strstr(github_ref, "/continuous/")) { + if (strcmp(github_ref, "") != 0 && strstr(github_ref, "/continuous/") != NULL) { channel = "latest"; } else { channel = "continuous"; From b0d2f01a17106c7ece47b762563f10791df1a2b1 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 16:34:50 +0300 Subject: [PATCH 11/16] style: follow C conventions of constant naming (Uppercase, move constant to top of file) --- src/appimagetool.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 985364df5..ea28b03e0 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -70,8 +70,12 @@ enum fARCH { }; static gchar const APPIMAGEIGNORE[] = ".appimageignore"; -static char _exclude_file_desc[256]; +// maximum size that the updateinformation's buffer can hold +// TODO: why 1024? +const int UPDATE_INFORMATION_BUFFER_SIZE = 1024; + +static char _exclude_file_desc[256]; static gboolean list = FALSE; static gboolean verbose = FALSE; static gboolean showVersionOnly = FALSE; @@ -825,7 +829,7 @@ main (int argc, char *argv[]) * should hopefully change that. */ fprintf (stderr, "Generating squashfs...\n"); - const int buffer_size = 1024; + int size = 0; @@ -873,7 +877,7 @@ main (int argc, char *argv[]) if(bintray_user != NULL){ if(bintray_repo != NULL){ - char buf[buffer_size]; + char buf[UPDATE_INFORMATION_BUFFER_SIZE]; sprintf(buf, "bintray-zsync|%s|%s|%s|%s-_latestVersion-%s.AppImage.zsync", bintray_user, bintray_repo, app_name_for_filename, app_name_for_filename, arch); updateinformation = buf; printf("%s\n", updateinformation); @@ -928,9 +932,9 @@ main (int argc, char *argv[]) } else { channel = "continuous"; } - int is_zsync_write_success = snprintf(buf, buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + int is_zsync_write_success = snprintf(buf, UPDATE_INFORMATION_BUFFER_SIZE, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { - printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", buffer_size); + printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", UPDATE_INFORMATION_BUFFER_SIZE); exit(is_zsync_write_success); } updateinformation = buf; From 5371a2a77638b8b321b2def6840634303db5d9c7 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 16:52:32 +0300 Subject: [PATCH 12/16] fix: explicitly check if zsyncmake_path is not NULL --- src/appimagetool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index ea28b03e0..8c42f91c7 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -919,7 +919,7 @@ main (int argc, char *argv[]) } else if (github_repository != NULL && github_ref != NULL) { printf("Running on GitHub Actions\n"); gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); - if (zsyncmake_path) { + if (zsyncmake_path != NULL) { if (strstr(github_ref, "/pull/") != NULL) { printf("Will not calculate update information for GitHub because this is a pull request\n"); } else { From 8550ec688f333324df7c47ff064c3f907e18a9a0 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 17:45:42 +0300 Subject: [PATCH 13/16] fix: remove an additional check for empty string. we already checked if github_ref was NULL --- src/appimagetool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 8c42f91c7..9faa7f9a9 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -926,8 +926,8 @@ main (int argc, char *argv[]) printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); char buf[1024]; gchar **parts = g_strsplit (github_repository, "/", 2); - char* channel; - if (strcmp(github_ref, "") != 0 && strstr(github_ref, "/continuous/") != NULL) { + const char* channel; + if (strstr(github_ref, "/continuous/") != NULL) { channel = "latest"; } else { channel = "continuous"; From 0d4bac37107ae4ea2c21930f411c0859d9c3ef58 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 17:53:54 +0300 Subject: [PATCH 14/16] style: move update_information_buffer_size to a position prior to use instead of defining it globally --- src/appimagetool.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 9faa7f9a9..88138277d 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -71,10 +71,6 @@ enum fARCH { static gchar const APPIMAGEIGNORE[] = ".appimageignore"; -// maximum size that the updateinformation's buffer can hold -// TODO: why 1024? -const int UPDATE_INFORMATION_BUFFER_SIZE = 1024; - static char _exclude_file_desc[256]; static gboolean list = FALSE; static gboolean verbose = FALSE; @@ -874,10 +870,13 @@ main (int argc, char *argv[]) exit(1); } + // maximum size that the updateinformation's buffer can hold + // TODO: why 1024? + const int update_information_buffer_size = 1024; if(bintray_user != NULL){ if(bintray_repo != NULL){ - char buf[UPDATE_INFORMATION_BUFFER_SIZE]; + char buf[update_information_buffer_size]; sprintf(buf, "bintray-zsync|%s|%s|%s|%s-_latestVersion-%s.AppImage.zsync", bintray_user, bintray_repo, app_name_for_filename, app_name_for_filename, arch); updateinformation = buf; printf("%s\n", updateinformation); @@ -932,9 +931,9 @@ main (int argc, char *argv[]) } else { channel = "continuous"; } - int is_zsync_write_success = snprintf(buf, UPDATE_INFORMATION_BUFFER_SIZE, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + int is_zsync_write_success = snprintf(buf, update_information_buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { - printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", UPDATE_INFORMATION_BUFFER_SIZE); + printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", update_information_buffer_size); exit(is_zsync_write_success); } updateinformation = buf; From 27113a82609ec14d6bc9d8c138d00fe1dc838274 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 18:50:24 +0300 Subject: [PATCH 15/16] style: use updateinformation_buffer instead of an ambiguous variable name 'buf' --- src/appimagetool.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/appimagetool.c b/src/appimagetool.c index 88138277d..790ce94dc 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -876,9 +876,9 @@ main (int argc, char *argv[]) if(bintray_user != NULL){ if(bintray_repo != NULL){ - char buf[update_information_buffer_size]; - sprintf(buf, "bintray-zsync|%s|%s|%s|%s-_latestVersion-%s.AppImage.zsync", bintray_user, bintray_repo, app_name_for_filename, app_name_for_filename, arch); - updateinformation = buf; + char updateinformation_buffer[update_information_buffer_size]; + sprintf(updateinformation_buffer, "bintray-zsync|%s|%s|%s|%s-_latestVersion-%s.AppImage.zsync", bintray_user, bintray_repo, app_name_for_filename, app_name_for_filename, arch); + updateinformation = updateinformation_buffer; printf("%s\n", updateinformation); } } @@ -897,7 +897,7 @@ main (int argc, char *argv[]) } else { gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); if(zsyncmake_path){ - char buf[1024]; + char updateinformation_buffer[1024]; gchar **parts = g_strsplit (travis_repo_slug, "/", 2); /* https://github.com/AppImage/AppImageSpec/blob/master/draft.md#github-releases * gh-releases-zsync|probono|AppImages|latest|Subsurface*-x86_64.AppImage.zsync */ @@ -907,8 +907,8 @@ main (int argc, char *argv[]) channel = "latest"; } } - sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); - updateinformation = buf; + sprintf(updateinformation_buffer, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + updateinformation = updateinformation_buffer; printf("Guessing update information based on $TRAVIS_TAG=%s and $TRAVIS_REPO_SLUG=%s\n", travis_tag, travis_repo_slug); printf("%s\n", updateinformation); } else { @@ -923,7 +923,7 @@ main (int argc, char *argv[]) printf("Will not calculate update information for GitHub because this is a pull request\n"); } else { printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); - char buf[1024]; + char updateinformation_buffer[1024]; gchar **parts = g_strsplit (github_repository, "/", 2); const char* channel; if (strstr(github_ref, "/continuous/") != NULL) { @@ -931,12 +931,12 @@ main (int argc, char *argv[]) } else { channel = "continuous"; } - int is_zsync_write_success = snprintf(buf, update_information_buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); + int is_zsync_write_success = snprintf(updateinformation_buffer, update_information_buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", update_information_buffer_size); exit(is_zsync_write_success); } - updateinformation = buf; + updateinformation = updateinformation_buffer; printf("%s\n", updateinformation); } } else { From 6d00122b145da8b8fb47cba85e775b4dedf25dd7 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 22 Nov 2020 19:16:01 +0300 Subject: [PATCH 16/16] fix: free unused pointers once processing is complete using g_strfreev --- src/appimagetool.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/appimagetool.c b/src/appimagetool.c index 790ce94dc..6eed90457 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -917,7 +917,9 @@ main (int argc, char *argv[]) } } else if (github_repository != NULL && github_ref != NULL) { printf("Running on GitHub Actions\n"); + // get path to zsyncmake gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake"); + if (zsyncmake_path != NULL) { if (strstr(github_ref, "/pull/") != NULL) { printf("Will not calculate update information for GitHub because this is a pull request\n"); @@ -925,17 +927,23 @@ main (int argc, char *argv[]) printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref); char updateinformation_buffer[1024]; gchar **parts = g_strsplit (github_repository, "/", 2); + const char* channel; if (strstr(github_ref, "/continuous/") != NULL) { channel = "latest"; } else { channel = "continuous"; } + int is_zsync_write_success = snprintf(updateinformation_buffer, update_information_buffer_size, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch); if (is_zsync_write_success < 0) { printf("Writing updateinformation failed. zsync information is too long. (> %d)\n", update_information_buffer_size); exit(is_zsync_write_success); } + + // free the pointers from g_strsplit, to avoid a memort leak + g_strfreev(parts); + updateinformation = updateinformation_buffer; printf("%s\n", updateinformation); }