summaryrefslogtreecommitdiff
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-3f4e55a8722fef13b6f5dd3996fb082c7de2fc57.tar.gz
rockbox-3f4e55a8722fef13b6f5dd3996fb082c7de2fc57.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 @@
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
@@ -351,11 +351,16 @@ static bool generate_bookmark_file_name(char *filenamebuf,
351 strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz); 351 strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz);
352 else 352 else
353 { 353 {
354 filenamebufsz--; /* strlcpy considers the NULL so bmarknamelen is one off */ 354 size_t buflen, len;
355 size_t len = strlcpy(filenamebuf, bmarknamein, 355 /* strmemccpy considers the NULL so bmarknamelen is one off */
356 MIN(filenamebufsz, bmarknamelen) + 1); 356 buflen = MIN(filenamebufsz -1 , bmarknamelen);
357 if(len >= filenamebufsz) 357 if (buflen >= filenamebufsz)
358 return false; 358 return false;
359
360 strmemccpy(filenamebuf, bmarknamein, buflen + 1);
361
362 len = strlen(filenamebuf);
363
359#ifdef HAVE_MULTIVOLUME 364#ifdef HAVE_MULTIVOLUME
360 /* The "root" of an extra volume need special handling too. */ 365 /* The "root" of an extra volume need special handling too. */
361 const char *filename; 366 const char *filename;
@@ -404,7 +409,7 @@ static char* create_bookmark(char **name, size_t *namelen)
404 if(!resume_info.id3) 409 if(!resume_info.id3)
405 return NULL; 410 return NULL;
406 411
407 size_t bmsz = snprintf(buf, bufsz, 412 size_t bmarksz= snprintf(buf, bufsz,
408 /* new optional bookmark token descriptors should 413 /* new optional bookmark token descriptors should
409 be inserted just after ';"' in this line... */ 414 be inserted just after ';"' in this line... */
410#if defined(HAVE_PITCHCONTROL) 415#if defined(HAVE_PITCHCONTROL)
@@ -431,20 +436,20 @@ static char* create_bookmark(char **name, size_t *namelen)
431#endif 436#endif
432 ); /*sprintf*/ 437 ); /*sprintf*/
433/* mandatory tokens */ 438/* mandatory tokens */
434 if (bmsz >= bufsz) /* include NULL*/ 439 if (bmarksz >= bufsz) /* include NULL*/
435 return NULL; 440 return NULL;
436 buf += bmsz; 441 buf += bmarksz;
437 bufsz -= bmsz; 442 bufsz -= bmarksz;
438 443
439 /* create the bookmark */ 444 /* create the bookmark */
440 playlist_get_name(NULL, buf, bmsz); 445 playlist_get_name(NULL, buf, bufsz);
441 bmsz = strlen(buf); 446 bmarksz = strlen(buf);
442 447
443 if (bmsz == 0 || (bmsz + 1) >= bufsz) /* include the separator & NULL*/ 448 if (bmarksz == 0 || (bmarksz + 1) >= bufsz) /* include the separator & NULL*/
444 return NULL; 449 return NULL;
445 450
446 *name = buf; /* return the playlist name through the *pointer */ 451 *name = buf; /* return the playlist name through the *pointer */
447 *namelen = bmsz; /* return the name length through the pointer */ 452 *namelen = bmarksz; /* return the name length through the pointer */
448 453
449 /* Get the currently playing file minus the path */ 454 /* Get the currently playing file minus the path */
450 /* This is used when displaying the available bookmarks */ 455 /* This is used when displaying the available bookmarks */
@@ -452,12 +457,12 @@ static char* create_bookmark(char **name, size_t *namelen)
452 if(NULL == file) 457 if(NULL == file)
453 return NULL; 458 return NULL;
454 459
455 if (buf[bmsz - 1] != '/') 460 if (buf[bmarksz - 1] != '/')
456 file = resume_info.id3->path; 461 file = resume_info.id3->path;
457 else file++; 462 else file++;
458 463
459 buf += bmsz; 464 buf += bmarksz;
460 bufsz -= (bmsz + 1); 465 bufsz -= (bmarksz + 1);
461 buf[0] = ';'; 466 buf[0] = ';';
462 buf[1] = '\0'; 467 buf[1] = '\0';
463 468