summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-27 00:35:34 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2022-11-27 02:05:34 -0500
commit3f4e55a8722fef13b6f5dd3996fb082c7de2fc57 (patch)
treee5b8261def9cb23a8f054e534e3ccf6eb82b9d0c
parent65db4acabefdc9cbccc247d598b7416be4431542 (diff)
downloadrockbox-3f4e55a872.tar.gz
rockbox-3f4e55a872.zip
bookmark.c fix bookmark.c fix filename generator #2
strlcpy returns the size of the string it tried to create so we still need strlen since we know what the sizes are of the strings just check for overflow first and use strmemccpy fix bufsz on playlist_get_name() Change-Id: Iaa52f869994ca94487c19b0cf2958330db4fc786
-rw-r--r--apps/bookmark.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index d3e7cf3db8..77aaa4377e 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -43,7 +43,7 @@
#include "file.h"
#include "pathfuncs.h"
-/* #define LOGF_ENABLE */
+/*#define LOGF_ENABLE*/
#include "logf.h"
#define MAX_BOOKMARKS 10
@@ -351,11 +351,16 @@ static bool generate_bookmark_file_name(char *filenamebuf,
strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz);
else
{
- filenamebufsz--; /* strlcpy considers the NULL so bmarknamelen is one off */
- size_t len = strlcpy(filenamebuf, bmarknamein,
- MIN(filenamebufsz, bmarknamelen) + 1);
- if(len >= filenamebufsz)
+ size_t buflen, len;
+ /* strmemccpy considers the NULL so bmarknamelen is one off */
+ buflen = MIN(filenamebufsz -1 , bmarknamelen);
+ if (buflen >= filenamebufsz)
return false;
+
+ strmemccpy(filenamebuf, bmarknamein, buflen + 1);
+
+ len = strlen(filenamebuf);
+
#ifdef HAVE_MULTIVOLUME
/* The "root" of an extra volume need special handling too. */
const char *filename;
@@ -404,7 +409,7 @@ static char* create_bookmark(char **name, size_t *namelen)
if(!resume_info.id3)
return NULL;
- size_t bmsz = snprintf(buf, bufsz,
+ size_t bmarksz= snprintf(buf, bufsz,
/* new optional bookmark token descriptors should
be inserted just after ';"' in this line... */
#if defined(HAVE_PITCHCONTROL)
@@ -431,20 +436,20 @@ static char* create_bookmark(char **name, size_t *namelen)
#endif
); /*sprintf*/
/* mandatory tokens */
- if (bmsz >= bufsz) /* include NULL*/
+ if (bmarksz >= bufsz) /* include NULL*/
return NULL;
- buf += bmsz;
- bufsz -= bmsz;
+ buf += bmarksz;
+ bufsz -= bmarksz;
/* create the bookmark */
- playlist_get_name(NULL, buf, bmsz);
- bmsz = strlen(buf);
+ playlist_get_name(NULL, buf, bufsz);
+ bmarksz = strlen(buf);
- if (bmsz == 0 || (bmsz + 1) >= bufsz) /* include the separator & NULL*/
+ if (bmarksz == 0 || (bmarksz + 1) >= bufsz) /* include the separator & NULL*/
return NULL;
*name = buf; /* return the playlist name through the *pointer */
- *namelen = bmsz; /* return the name length through the pointer */
+ *namelen = bmarksz; /* return the name length through the pointer */
/* Get the currently playing file minus the path */
/* This is used when displaying the available bookmarks */
@@ -452,12 +457,12 @@ static char* create_bookmark(char **name, size_t *namelen)
if(NULL == file)
return NULL;
- if (buf[bmsz - 1] != '/')
+ if (buf[bmarksz - 1] != '/')
file = resume_info.id3->path;
else file++;
- buf += bmsz;
- bufsz -= (bmsz + 1);
+ buf += bmarksz;
+ bufsz -= (bmarksz + 1);
buf[0] = ';';
buf[1] = '\0';