main: replace sprintf with safer snprintf

This commit is contained in:
Andrey Skvortsov
2025-05-29 00:10:50 +03:00
committed by Martijn Braam
parent 886fea58bd
commit 5f2b7136ca

View File

@@ -318,7 +318,7 @@ struct capture_completed_args {
static bool static bool
capture_completed(struct capture_completed_args *args) capture_completed(struct capture_completed_args *args)
{ {
strncpy(last_path, args->fname, 259); snprintf(last_path, sizeof(last_path), args->fname);
gtk_image_set_from_paintable(GTK_IMAGE(thumb_last), gtk_image_set_from_paintable(GTK_IMAGE(thumb_last),
GDK_PAINTABLE(args->thumb)); GDK_PAINTABLE(args->thumb));
@@ -618,7 +618,7 @@ run_open_last_action(GSimpleAction *action, GVariant *param, gpointer user_data)
if (strlen(last_path) == 0) { if (strlen(last_path) == 0) {
return; return;
} }
sprintf(uri, "file://%s", last_path); snprintf(uri, sizeof(uri), "file://%s", last_path);
if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) { if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) {
g_printerr("Could not launch image viewer for '%s': %s\n", g_printerr("Could not launch image viewer for '%s': %s\n",
uri, uri,
@@ -631,7 +631,7 @@ run_open_photos_action(GSimpleAction *action, GVariant *param, gpointer user_dat
{ {
char uri[270]; char uri[270];
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
sprintf(uri, "file://%s", g_get_user_special_dir(G_USER_DIRECTORY_PICTURES)); snprintf(uri, sizeof(uri), "file://%s", g_get_user_special_dir(G_USER_DIRECTORY_PICTURES));
if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) { if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) {
g_printerr("Could not launch image viewer: %s\n", error->message); g_printerr("Could not launch image viewer: %s\n", error->message);
} }