summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-03-30 01:04:51 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2023-03-30 01:04:51 -0400
commit2456d28e2176b1a1616aa62c5956fa3c2fac0ee3 (patch)
treecf08dccaad8a5f8685d9225708f6eed1d5b2f7bd
parenta2e5d9563f9dec84907f4f2060af6dfad895c4ba (diff)
downloadrockbox-2456d28e21.tar.gz
rockbox-2456d28e21.zip
[BugFix] open_plugin didn't recognize opx shortcuts
opx shortcuts allow an easy way to add parameters to plugins you should be able to set them as shortcuts now the plugin hd a use after free bug on the dat file file descriptor Change-Id: I5fe3b0628e7da003c03b9b54f5788b0d0dbfea74
-rw-r--r--apps/open_plugin.c37
-rw-r--r--apps/plugins/open_plugins.c10
2 files changed, 27 insertions, 20 deletions
diff --git a/apps/open_plugin.c b/apps/open_plugin.c
index 46b6007ee2..1256db79f8 100644
--- a/apps/open_plugin.c
+++ b/apps/open_plugin.c
@@ -304,12 +304,8 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
op_update_dat(op_entry, true);
}
- if (plugin)
+ while (plugin)
{
- op_entry->hash = hash;
- op_entry->lang_id = lang_id;
- op_entry->checksum = open_plugin_csum +
- (lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY);
/* name */
if (path_basename(plugin, (const char **)&pos) == 0)
pos = "\0";
@@ -323,28 +319,33 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
if(!parameter)
parameter = "";
strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ);
- goto retnhash;
}
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0)
{
+ /* get the entry from the opx file */
op_load_entry(0, OPEN_PLUGIN_LANG_IGNORE, op_entry, plugin);
- goto retnhash;
}
+ else
+ {
+ break;
+ }
+ op_entry->hash = hash;
+ op_entry->lang_id = lang_id;
+ op_entry->checksum = open_plugin_csum +
+ (lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY);
+ logf("OP add_path name: %s %s %s",
+ op_entry->name, op_entry->path, op_entry->param);
+ return hash;
}
logf("OP add_path Invalid, *Clearing entry*");
if (lang_id != LANG_SHORTCUTS) /* from shortcuts menu */
splashf(HZ * 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos);
op_clear_entry(op_entry);
- hash = 0;
-
-retnhash:
- logf("OP add_path name: %s %s %s",
- op_entry->name, op_entry->path, op_entry->param);
- return hash;
+ return 0;
}
-/* only displays directories and .rock files */
+/* only displays directories, .rock, and .opx files */
static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{
(void)name;
@@ -358,6 +359,10 @@ static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{
return true;
}
+ else if(attr & FILE_ATTR_OPX)
+ {
+ return true;
+ }
return false;
}
@@ -375,7 +380,7 @@ void open_plugin_browse(const char *key)
struct open_plugin_entry_t *op_entry = open_plugin_get_entry();
logf("OP browse key: %s name: %s",
- (key ? P2STR((unsigned char *)key):"No Key"), open_plugin_entry.name);
+ (key ? P2STR((unsigned char *)key):"No Key"), op_entry->name);
logf("OP browse %s %s", op_entry->path, op_entry->param);
if (op_entry->path[0] == '\0' || !file_exists(op_entry->path))
@@ -399,7 +404,7 @@ void open_plugin_browse(const char *key)
/* open_plugin_load_entry()
* recall of the plugin path and parameters based on supplied key
* returns the index in OPEN_PLUGIN_DAT where the entry was found (>= 0)
-* if the entry was found but has not been saved returns OPEN_PLUGIN_NEEDS_FLUSHED
+* if the entry was found but has not been saved returns OPEN_PLUGIN_NEEDS_FLUSHED
* otherwise returns OPEN_PLUGIN_NOT_FOUND (< 0) if key was not found
*/
int open_plugin_load_entry(const char *key)
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c
index a4b19d558f..b608aff789 100644
--- a/apps/plugins/open_plugins.c
+++ b/apps/plugins/open_plugins.c
@@ -101,7 +101,7 @@ static bool op_entry_read(int fd, int selected_item, off_t data_sz)
{
rb->memset(&op_entry, 0, op_entry_sz);
op_entry.lang_id = -1;
- return ((selected_item >= 0) &&
+ return ((selected_item >= 0) && (fd >= 0) &&
(rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) &&
(rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 0);
}
@@ -196,7 +196,7 @@ static int op_entry_set_path(void)
struct browse_context browse = {
.dirfilter = SHOW_ALL,
- .flags = BROWSE_SELECTONLY,
+ .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER,
.title = rb->str(LANG_ADD),
.icon = Icon_Plugin,
.root = op_entry.path,
@@ -225,7 +225,7 @@ static int op_entry_set_param_path(void)
struct browse_context browse = {
.dirfilter = SHOW_ALL,
- .flags = BROWSE_SELECTONLY,
+ .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER,
.title = rb->str(LANG_PARAMETER),
.icon = Icon_Plugin,
.root = tmp_buf,
@@ -412,6 +412,7 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha
{
rb->close(fd_tmp);
rb->close(fd_dat);
+ fd_dat = -1;
rb->remove(OPEN_PLUGIN_DAT);
rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
}
@@ -468,7 +469,7 @@ static void op_entry_remove(int selection)
static void op_entry_remove_empty(void)
{
bool resave = false;
- if (fd_dat && rb->lseek(fd_dat, 0, SEEK_SET) == 0)
+ if (fd_dat >= 0 && rb->lseek(fd_dat, 0, SEEK_SET) == 0)
{
while (resave == false &&
rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz)
@@ -489,6 +490,7 @@ static void op_entry_remove_empty(void)
{
rb->close(fd_tmp);
rb->close(fd_dat);
+ fd_dat = -1;
rb->remove(OPEN_PLUGIN_DAT);
rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
}