Skip to content

Commit 5336791

Browse files
committed
fix(application): don't save image if file path was truncated
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
1 parent 2d4bcc2 commit 5336791

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pixbuf.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder,
4848
char *filename_format) {
4949
char path[MAX_PATH];
5050
char *filename;
51+
int rc;
5152
filename = format_filename(filename_format);
5253
if (filename == NULL) return;
5354

54-
g_snprintf(path, MAX_PATH, "%s/%s", folder, filename);
55+
rc = g_snprintf(path, MAX_PATH, "%s/%s", folder, filename);
5556
g_free(filename);
57+
/* valid range of rc is 1 byte to (MAX_PATH-1) */
58+
if (rc < 0) {
59+
g_warning("error while building output file path: %s", g_strerror(errno));
60+
return;
61+
} else if (rc >= MAX_PATH) {
62+
g_warning("not writing file because output file path was truncated");
63+
return;
64+
}
65+
5666
g_info("saving surface to path: %s", path);
5767
write_file(pixbuf, path);
5868
}

0 commit comments

Comments
 (0)