mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
4ecf3970a6
commit
b11777b06c
1 changed files with 10 additions and 3 deletions
|
@ -43,7 +43,7 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "pathfuncs.h"
|
#include "pathfuncs.h"
|
||||||
|
|
||||||
/*#define LOGF_ENABLE*/
|
/* #define LOGF_ENABLE */
|
||||||
#include "logf.h"
|
#include "logf.h"
|
||||||
|
|
||||||
#define MAX_BOOKMARKS 10
|
#define MAX_BOOKMARKS 10
|
||||||
|
@ -122,6 +122,7 @@ static bool bookmark_get_playlist_and_track(const char *bookmark,
|
||||||
char **pl_end,
|
char **pl_end,
|
||||||
char **track)
|
char **track)
|
||||||
{
|
{
|
||||||
|
logf("%s", __func__);
|
||||||
*pl_start = strchr(bookmark,'/');
|
*pl_start = strchr(bookmark,'/');
|
||||||
if (!(*pl_start))
|
if (!(*pl_start))
|
||||||
return false;
|
return false;
|
||||||
|
@ -217,6 +218,8 @@ static int open_temp_bookmark(char *buf,
|
||||||
int oflags,
|
int oflags,
|
||||||
const char* filename)
|
const char* filename)
|
||||||
{
|
{
|
||||||
|
if(filename[0] == '/')
|
||||||
|
filename++;
|
||||||
/* Opening up a temp bookmark file */
|
/* Opening up a temp bookmark file */
|
||||||
int fd = open_pathfmt(buf, bufsz, oflags, "/%s.tmp", filename);
|
int fd = open_pathfmt(buf, bufsz, oflags, "/%s.tmp", filename);
|
||||||
#ifdef LOGF_ENABLE
|
#ifdef LOGF_ENABLE
|
||||||
|
@ -348,8 +351,9 @@ static bool generate_bookmark_file_name(char *filenamebuf,
|
||||||
strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz);
|
strmemccpy(filenamebuf, "/root_dir.bmark", filenamebufsz);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
filenamebufsz--; /* strlcpy considers the NULL so bmarknamelen is one off */
|
||||||
size_t len = strlcpy(filenamebuf, bmarknamein,
|
size_t len = strlcpy(filenamebuf, bmarknamein,
|
||||||
MIN(filenamebufsz, bmarknamelen));
|
MIN(filenamebufsz, bmarknamelen) + 1);
|
||||||
if(len >= filenamebufsz)
|
if(len >= filenamebufsz)
|
||||||
return false;
|
return false;
|
||||||
#ifdef HAVE_MULTIVOLUME
|
#ifdef HAVE_MULTIVOLUME
|
||||||
|
@ -360,7 +364,6 @@ static bool generate_bookmark_file_name(char *filenamebuf,
|
||||||
#endif
|
#endif
|
||||||
if(filenamebuf[len-1] == '/') {
|
if(filenamebuf[len-1] == '/') {
|
||||||
filenamebuf[len-1] = '\0';
|
filenamebuf[len-1] = '\0';
|
||||||
len--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *name = ".bmark";
|
const char *name = ".bmark";
|
||||||
|
@ -484,6 +487,7 @@ static char* create_bookmark(char **name, size_t *namelen)
|
||||||
/* ------------------------------------------------------------------------*/
|
/* ------------------------------------------------------------------------*/
|
||||||
static bool write_bookmark(bool create_bookmark_file)
|
static bool write_bookmark(bool create_bookmark_file)
|
||||||
{
|
{
|
||||||
|
logf("%s", __func__);
|
||||||
char bm_filename[MAX_PATH];
|
char bm_filename[MAX_PATH];
|
||||||
bool ret=true;
|
bool ret=true;
|
||||||
|
|
||||||
|
@ -1082,6 +1086,7 @@ bool bookmark_mrb_load()
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
bool bookmark_autobookmark(bool prompt_ok)
|
bool bookmark_autobookmark(bool prompt_ok)
|
||||||
{
|
{
|
||||||
|
logf("%s", __func__);
|
||||||
bool update;
|
bool update;
|
||||||
|
|
||||||
if (!bookmark_is_bookmarkable_state())
|
if (!bookmark_is_bookmarkable_state())
|
||||||
|
@ -1127,6 +1132,7 @@ bool bookmark_autobookmark(bool prompt_ok)
|
||||||
/* ------------------------------------------------------------------------*/
|
/* ------------------------------------------------------------------------*/
|
||||||
int bookmark_autoload(const char* file)
|
int bookmark_autoload(const char* file)
|
||||||
{
|
{
|
||||||
|
logf("%s", __func__);
|
||||||
char bm_filename[MAX_PATH];
|
char bm_filename[MAX_PATH];
|
||||||
char* bookmark;
|
char* bookmark;
|
||||||
|
|
||||||
|
@ -1176,6 +1182,7 @@ int bookmark_autoload(const char* file)
|
||||||
/* ------------------------------------------------------------------------*/
|
/* ------------------------------------------------------------------------*/
|
||||||
bool bookmark_load(const char* file, bool autoload)
|
bool bookmark_load(const char* file, bool autoload)
|
||||||
{
|
{
|
||||||
|
logf("%s", __func__);
|
||||||
int fd;
|
int fd;
|
||||||
char* bookmark = NULL;
|
char* bookmark = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue