From 3745c813f924b12232c4f37610aecd23fe5654b8 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 23 Nov 2022 21:46:13 -0500 Subject: misc.c open_pathfmt caller supplied buffer Amachronic raised concern about open() blocking causing a static buf to get overwritten in multiple calls its prudent to just have the caller supply the buffer to minimize stack issues later Change-Id: Iae27c7d063adb1a65688f920f6aa5c395fa5694a --- apps/bookmark.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'apps/bookmark.c') diff --git a/apps/bookmark.c b/apps/bookmark.c index 20841b4940..8256f76ef8 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -290,10 +290,8 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, bool equal; /* Opening up a temp bookmark file */ - snprintf(global_temp_buffer, sizeof(global_temp_buffer), - "%s.tmp", bookmark_file_name); - temp_bookmark_file = open(global_temp_buffer, - O_WRONLY | O_CREAT | O_TRUNC, 0666); + temp_bookmark_file = open_pathfmt(global_temp_buffer, sizeof(global_temp_buffer), + O_WRONLY | O_CREAT | O_TRUNC, "%s.tmp", bookmark_file_name); if (temp_bookmark_file < 0) return false; /* can't open the temp file */ @@ -893,10 +891,8 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) int bookmark_count = 0; /* Opening up a temp bookmark file */ - snprintf(global_temp_buffer, sizeof(global_temp_buffer), - "%s.tmp", bookmark_file_name); - temp_bookmark_file = open(global_temp_buffer, - O_WRONLY | O_CREAT | O_TRUNC, 0666); + temp_bookmark_file = open_pathfmt(global_temp_buffer, sizeof(global_temp_buffer), + O_WRONLY | O_CREAT | O_TRUNC, "%s.tmp", bookmark_file_name); if (temp_bookmark_file < 0) return false; /* can't open the temp file */ -- cgit v1.2.3