Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+34 -27
+4 -8
apps/bookmark.c
··· 290 290 bool equal; 291 291 292 292 /* Opening up a temp bookmark file */ 293 - snprintf(global_temp_buffer, sizeof(global_temp_buffer), 294 - "%s.tmp", bookmark_file_name); 295 - temp_bookmark_file = open(global_temp_buffer, 296 - O_WRONLY | O_CREAT | O_TRUNC, 0666); 293 + temp_bookmark_file = open_pathfmt(global_temp_buffer, sizeof(global_temp_buffer), 294 + O_WRONLY | O_CREAT | O_TRUNC, "%s.tmp", bookmark_file_name); 297 295 if (temp_bookmark_file < 0) 298 296 return false; /* can't open the temp file */ 299 297 ··· 893 891 int bookmark_count = 0; 894 892 895 893 /* Opening up a temp bookmark file */ 896 - snprintf(global_temp_buffer, sizeof(global_temp_buffer), 897 - "%s.tmp", bookmark_file_name); 898 - temp_bookmark_file = open(global_temp_buffer, 899 - O_WRONLY | O_CREAT | O_TRUNC, 0666); 894 + temp_bookmark_file = open_pathfmt(global_temp_buffer, sizeof(global_temp_buffer), 895 + O_WRONLY | O_CREAT | O_TRUNC, "%s.tmp", bookmark_file_name); 900 896 901 897 if (temp_bookmark_file < 0) 902 898 return false; /* can't open the temp file */
+2 -1
apps/debug_menu.c
··· 2307 2307 return false; 2308 2308 2309 2309 #if CONFIG_RTC 2310 + char fname[MAX_PATH]; 2310 2311 struct tm *nowtm = get_time(); 2311 - fd = open_pathfmt(O_CREAT|O_WRONLY|O_TRUNC, 2312 + fd = open_pathfmt(fname, sizeof(fname), O_CREAT|O_WRONLY|O_TRUNC, 2312 2313 "%s/boostlog_%04d%02d%02d%02d%02d%02d.txt", ROCKBOX_DIR, 2313 2314 nowtm->tm_year + 1900, nowtm->tm_mon + 1, nowtm->tm_mday, 2314 2315 nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec);
+5 -4
apps/filetypes.c
··· 325 325 if (!global_settings.colors_file[0] || global_settings.colors_file[0] == '-') 326 326 return; 327 327 328 - fd = open_pathfmt(O_RDONLY, THEME_DIR "/%s.colours", 329 - global_settings.colors_file); 328 + fd = open_pathfmt(buffer, sizeof(buffer), O_RDONLY, 329 + THEME_DIR "/%s.colours", global_settings.colors_file); 330 330 if (fd < 0) 331 331 return; 332 332 while (read_line(fd, buffer, MAX_PATH) > 0) ··· 365 365 custom_filetype_icons[i] = filetypes[i].icon; 366 366 } 367 367 368 - fd = open_pathfmt(O_RDONLY, "%s/%s.icons", ICON_DIR, 369 - global_settings.viewers_icon_file); 368 + fd = open_pathfmt(buffer, sizeof(buffer), O_RDONLY, 369 + ICON_DIR "/%s.icons", global_settings.viewers_icon_file); 370 370 if (fd < 0) 371 371 return; 372 + 372 373 while (read_line(fd, buffer, MAX_PATH) > 0) 373 374 { 374 375 if (!settings_parseline(buffer, &ext, &icon))
+3 -1
apps/gui/icon.c
··· 182 182 ic->handle = 0; 183 183 if (filename[0] && filename[0] != '-') 184 184 { 185 - fd = open_pathfmt(O_RDONLY, ICON_DIR "/%s.bmp", filename); 185 + char fname[MAX_PATH]; 186 + fd = open_pathfmt(fname, sizeof(fname), O_RDONLY, 187 + ICON_DIR "/%s.bmp", filename); 186 188 if (fd < 0) 187 189 return; 188 190 buf_size = read_bmp_fd(fd, &ic->bmp, 0,
+2 -1
apps/logfdisp.c
··· 225 225 logfenabled = false; 226 226 227 227 #if CONFIG_RTC 228 + char fname[MAX_PATH]; 228 229 struct tm *nowtm = get_time(); 229 - fd = open_pathfmt(O_CREAT|O_WRONLY|O_TRUNC, 230 + fd = open_pathfmt(fname, sizeof(fname), O_CREAT|O_WRONLY|O_TRUNC, 230 231 "%s/logf_%04d%02d%02d%02d%02d%02d.txt", ROCKBOX_DIR, 231 232 nowtm->tm_year + 1900, nowtm->tm_mon + 1, nowtm->tm_mday, 232 233 nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec);
+2 -3
apps/misc.c
··· 1419 1419 } 1420 1420 1421 1421 /* open but with a builtin printf for assembling the path */ 1422 - int open_pathfmt(int oflag, const char *pathfmt, ...) 1422 + int open_pathfmt(char *buf, size_t size, int oflag, const char *pathfmt, ...) 1423 1423 { 1424 - static char buf[MAX_PATH]; 1425 1424 va_list ap; 1426 1425 va_start(ap, pathfmt); 1427 - vsnprintf(buf, sizeof(buf), pathfmt, ap); 1426 + vsnprintf(buf, size, pathfmt, ap); 1428 1427 va_end(ap); 1429 1428 return open(buf, oflag, 0666); 1430 1429 }
+1 -1
apps/misc.h
··· 122 122 #define BOM_UTF_16_SIZE 2 123 123 124 124 int split_string(char *str, const char needle, char *vector[], int vector_length); 125 - int open_pathfmt(int oflag, const char *pathfmt, ...); 125 + int open_pathfmt(char *buf, size_t size, int oflag, const char *pathfmt, ...); 126 126 int open_utf8(const char* pathname, int flags); 127 127 int string_option(const char *option, const char *const oplist[], bool ignore_case); 128 128
+12 -7
apps/tagcache.c
··· 423 423 { 424 424 int fd; 425 425 int rc; 426 + char fname[MAX_PATH]; 426 427 427 428 if (TAGCACHE_IS_NUMERIC(tag) || tag < 0 || tag >= TAG_COUNT) 428 429 return -1; 429 430 430 - fd = open_pathfmt(write ? O_RDWR : O_RDONLY, TAGCACHE_FILE_INDEX, tag); 431 + fd = open_pathfmt(fname, sizeof(fname), 432 + write ? O_RDWR : O_RDONLY, TAGCACHE_FILE_INDEX, tag); 431 433 432 434 if (fd < 0) 433 435 { ··· 803 805 { 804 806 if (tcs->idxfd[tag] < 0) 805 807 { 806 - tcs->idxfd[tag] = open_pathfmt(O_RDONLY, TAGCACHE_FILE_INDEX, tag); 808 + char fname[MAX_PATH]; 809 + tcs->idxfd[tag] = open_pathfmt(fname, sizeof(fname), 810 + O_RDONLY, TAGCACHE_FILE_INDEX, tag); 807 811 } 808 812 809 813 if (tcs->idxfd[tag] < 0) ··· 1583 1587 } 1584 1588 1585 1589 if (!TAGCACHE_IS_NUMERIC(clause->tag) && tcs->idxfd[clause->tag] < 0) 1586 - { 1587 - tcs->idxfd[clause->tag] = open_pathfmt(O_RDONLY, 1588 - TAGCACHE_FILE_INDEX, clause->tag); 1590 + { 1591 + char fname[MAX_PATH]; 1592 + tcs->idxfd[clause->tag] = open_pathfmt(fname, sizeof(fname), O_RDONLY, 1593 + TAGCACHE_FILE_INDEX, clause->tag); 1589 1594 } 1590 1595 } 1591 1596 ··· 2743 2748 * Creating new index file to store the tags. No need to preload 2744 2749 * anything whether the index type is sorted or not. 2745 2750 */ 2746 - fd = open_pathfmt(O_WRONLY | O_CREAT | O_TRUNC, 2751 + fd = open_pathfmt(buf, bufsz, O_WRONLY | O_CREAT | O_TRUNC, 2747 2752 TAGCACHE_FILE_INDEX, index_type); 2748 2753 if (fd < 0) 2749 2754 { ··· 4401 4406 4402 4407 logf("reverse scan..."); 4403 4408 4404 - fd = open_pathfmt(O_RDONLY, TAGCACHE_FILE_INDEX, tag_filename); 4409 + fd = open_pathfmt(buf, bufsz, O_RDONLY, TAGCACHE_FILE_INDEX, tag_filename); 4405 4410 if (fd < 0) 4406 4411 { 4407 4412 logf(TAGCACHE_FILE_INDEX " open fail", tag_filename);
+3 -1
apps/talk.c
··· 247 247 248 248 static int open_voicefile(void) 249 249 { 250 + char fname[MAX_PATH]; 250 251 char* p_lang = DEFAULT_VOICE_LANG; /* default */ 251 252 252 253 if ( global_settings.lang_file[0] && ··· 255 256 p_lang = (char *)global_settings.lang_file; 256 257 } 257 258 258 - return open_pathfmt(O_RDONLY, LANG_DIR "/%s.voice", p_lang); 259 + return open_pathfmt(fname, sizeof(fname), 260 + O_RDONLY, LANG_DIR "/%s.voice", p_lang); 259 261 } 260 262 261 263