Skip to content

Commit c9b1a26

Browse files
committed
feat: Use snprintf instead of sprintf to avoid potential buffer overflow
#1075 (comment)
1 parent 628d171 commit c9b1a26

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/appimagetool.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,6 @@ main (int argc, char *argv[])
908908
printf("Will not guess update information since zsyncmake is missing\n");
909909
}
910910
}
911-
sprintf(buf, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch);
912911
} else if (github_repository != NULL && github_ref != NULL) {
913912
printf("Running on GitHub Actions\n");
914913
gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake");
@@ -925,6 +924,11 @@ main (int argc, char *argv[])
925924
} else {
926925
channel = "continuous";
927926
}
927+
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);
928+
if (is_zsync_write_success < 0) {
929+
printf("Writing updateinformation failed. zsync information is too long. (> 1024)\n");
930+
exit(is_zsync_write_success);
931+
}
928932
updateinformation = buf;
929933
printf("%s\n", updateinformation);
930934
}

0 commit comments

Comments
 (0)