diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-11-26 20:51:33 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-11-26 20:51:33 -0500 |
commit | b11777b06cc33724bd82f5a63c6ed64ca475af0b (patch) | |
tree | aa7d8d40346498f51827016e55f652842b2e009b | |
parent | 4ecf3970a6b71923d7b3fe51f72960cdda594fa4 (diff) | |
download | rockbox-b11777b06cc33724bd82f5a63c6ed64ca475af0b.tar.gz rockbox-b11777b06cc33724bd82f5a63c6ed64ca475af0b.zip |
bookmark.c fix off by one error in filename generator
strlcpy expects the buffer size so the name gets truncated by one character
Change-Id: I05ca0fed0a65a8b200f75b9647f7bf11407777a6
-rw-r--r-- | apps/bookmark.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c index f3c712240a..d3e7cf3db8 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c | |||
@@ -43,7 +43,7 @@ | |||
43 | #include "file.h" | 43 | #include "file.h" |
44 | #include "pathfuncs.h" | 44 | #include "pathfuncs.h" |
45 | 45 | ||
46 | /*#define LOGF_ENABLE*/ | 46 | /* #define LOGF_ENABLE */ |
47 | #include "logf.h" | 47 | #include "logf.h" |
48 | 48 | ||
49 | #define MAX_BOOKMARKS 10 | 49 | #define MAX_BOOKMARKS 10 |
@@ -122,6 +122,7 @@ static bool bookmark_get_playlist_and_track(const char *bookmark, | |||
122 | char **pl_end, | 122 | char **pl_end, |
123 | char **track) | 123 | char **track) |
124 | { | 124 | { |
125 | logf("%s", __func__); | ||
125 | *pl_start = strchr(bookmark,'/'); | 126 | *pl_start = strchr(bookmark,'/'); |
126 | if (!(*pl_start)) | 127 | if (!(*pl_start)) |
127 | return false; | 128 | return false; |
@@ -217,6 +218,8 @@ static int open_temp_bookmark(char *buf, | |||
217 | int oflags, | 218 | int oflags, |
218 | const char* filename) | 219 | const char* filename) |
219 | { | 220 | { |
221 | if(filename[0] == '/') | ||
222 | filename++; | ||
220 | /* Opening up a temp bookmark file */ | 223 | /* Opening up a temp bookmark file */ |
221 | int fd = open_pathfmt(buf, bufsz, oflags, "/%s.tmp", filename); | 224 | int fd = open_pathfmt(buf, bufsz, oflags, "/%s.tmp", filename); |
222 | #ifdef LOGF_ENABLE | 225 | #ifdef LOGF_ENABLE |
@@ -348,8 +351,9 @@ static bool generate_bookmark_file_name(char *filenamebuf, | |||
348 | strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz); | 351 | strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz); |
349 | else | 352 | else |
350 | { | 353 | { |
354 | filenamebufsz--; /* strlcpy considers the NULL so bmarknamelen is one off */ | ||
351 | size_t len = strlcpy(filenamebuf, bmarknamein, | 355 | size_t len = strlcpy(filenamebuf, bmarknamein, |
352 | MIN(filenamebufsz, bmarknamelen)); | 356 | MIN(filenamebufsz, bmarknamelen) + 1); |
353 | if(len >= filenamebufsz) | 357 | if(len >= filenamebufsz) |
354 | return false; | 358 | return false; |
355 | #ifdef HAVE_MULTIVOLUME | 359 | #ifdef HAVE_MULTIVOLUME |
@@ -360,7 +364,6 @@ static bool generate_bookmark_file_name(char *filenamebuf, | |||
360 | #endif | 364 | #endif |
361 | if(filenamebuf[len-1] == '/') { | 365 | if(filenamebuf[len-1] == '/') { |
362 | filenamebuf[len-1] = '\0'; | 366 | filenamebuf[len-1] = '\0'; |
363 | len--; | ||
364 | } | 367 | } |
365 | 368 | ||
366 | const char *name = ".bmark"; | 369 | const char *name = ".bmark"; |
@@ -484,6 +487,7 @@ static char* create_bookmark(char **name, size_t *namelen) | |||
484 | /* ------------------------------------------------------------------------*/ | 487 | /* ------------------------------------------------------------------------*/ |
485 | static bool write_bookmark(bool create_bookmark_file) | 488 | static bool write_bookmark(bool create_bookmark_file) |
486 | { | 489 | { |
490 | logf("%s", __func__); | ||
487 | char bm_filename[MAX_PATH]; | 491 | char bm_filename[MAX_PATH]; |
488 | bool ret=true; | 492 | bool ret=true; |
489 | 493 | ||
@@ -1082,6 +1086,7 @@ bool bookmark_mrb_load() | |||
1082 | /* ----------------------------------------------------------------------- */ | 1086 | /* ----------------------------------------------------------------------- */ |
1083 | bool bookmark_autobookmark(bool prompt_ok) | 1087 | bool bookmark_autobookmark(bool prompt_ok) |
1084 | { | 1088 | { |
1089 | logf("%s", __func__); | ||
1085 | bool update; | 1090 | bool update; |
1086 | 1091 | ||
1087 | if (!bookmark_is_bookmarkable_state()) | 1092 | if (!bookmark_is_bookmarkable_state()) |
@@ -1127,6 +1132,7 @@ bool bookmark_autobookmark(bool prompt_ok) | |||
1127 | /* ------------------------------------------------------------------------*/ | 1132 | /* ------------------------------------------------------------------------*/ |
1128 | int bookmark_autoload(const char* file) | 1133 | int bookmark_autoload(const char* file) |
1129 | { | 1134 | { |
1135 | logf("%s", __func__); | ||
1130 | char bm_filename[MAX_PATH]; | 1136 | char bm_filename[MAX_PATH]; |
1131 | char* bookmark; | 1137 | char* bookmark; |
1132 | 1138 | ||
@@ -1176,6 +1182,7 @@ int bookmark_autoload(const char* file) | |||
1176 | /* ------------------------------------------------------------------------*/ | 1182 | /* ------------------------------------------------------------------------*/ |
1177 | bool bookmark_load(const char* file, bool autoload) | 1183 | bool bookmark_load(const char* file, bool autoload) |
1178 | { | 1184 | { |
1185 | logf("%s", __func__); | ||
1179 | int fd; | 1186 | int fd; |
1180 | char* bookmark = NULL; | 1187 | char* bookmark = NULL; |
1181 | 1188 | ||