[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
This commit is contained in:
William Wilgus 2023-03-30 01:04:51 -04:00
parent a2e5d9563f
commit 2456d28e21
2 changed files with 27 additions and 20 deletions

View file

@ -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); 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 */ /* name */
if (path_basename(plugin, (const char **)&pos) == 0) if (path_basename(plugin, (const char **)&pos) == 0)
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) if(!parameter)
parameter = ""; parameter = "";
strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ); strmemccpy(op_entry->param, parameter, OPEN_PLUGIN_BUFSZ);
goto retnhash;
} }
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) 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); 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*"); logf("OP add_path Invalid, *Clearing entry*");
if (lang_id != LANG_SHORTCUTS) /* from shortcuts menu */ if (lang_id != LANG_SHORTCUTS) /* from shortcuts menu */
splashf(HZ * 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); splashf(HZ * 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos);
op_clear_entry(op_entry); op_clear_entry(op_entry);
hash = 0; return 0;
retnhash:
logf("OP add_path name: %s %s %s",
op_entry->name, op_entry->path, op_entry->param);
return hash;
} }
/* 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) static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{ {
(void)name; (void)name;
@ -358,6 +359,10 @@ static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{ {
return true; return true;
} }
else if(attr & FILE_ATTR_OPX)
{
return true;
}
return false; return false;
} }
@ -375,7 +380,7 @@ void open_plugin_browse(const char *key)
struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); struct open_plugin_entry_t *op_entry = open_plugin_get_entry();
logf("OP browse key: %s name: %s", 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); logf("OP browse %s %s", op_entry->path, op_entry->param);
if (op_entry->path[0] == '\0' || !file_exists(op_entry->path)) 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() /* open_plugin_load_entry()
* recall of the plugin path and parameters based on supplied key * recall of the plugin path and parameters based on supplied key
* returns the index in OPEN_PLUGIN_DAT where the entry was found (>= 0) * 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 * otherwise returns OPEN_PLUGIN_NOT_FOUND (< 0) if key was not found
*/ */
int open_plugin_load_entry(const char *key) int open_plugin_load_entry(const char *key)

View file

@ -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); rb->memset(&op_entry, 0, op_entry_sz);
op_entry.lang_id = -1; 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->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) &&
(rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 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 = { struct browse_context browse = {
.dirfilter = SHOW_ALL, .dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY, .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER,
.title = rb->str(LANG_ADD), .title = rb->str(LANG_ADD),
.icon = Icon_Plugin, .icon = Icon_Plugin,
.root = op_entry.path, .root = op_entry.path,
@ -225,7 +225,7 @@ static int op_entry_set_param_path(void)
struct browse_context browse = { struct browse_context browse = {
.dirfilter = SHOW_ALL, .dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY, .flags = BROWSE_SELECTONLY | BROWSE_DIRFILTER,
.title = rb->str(LANG_PARAMETER), .title = rb->str(LANG_PARAMETER),
.icon = Icon_Plugin, .icon = Icon_Plugin,
.root = tmp_buf, .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_tmp);
rb->close(fd_dat); rb->close(fd_dat);
fd_dat = -1;
rb->remove(OPEN_PLUGIN_DAT); rb->remove(OPEN_PLUGIN_DAT);
rb->rename(OPEN_PLUGIN_DAT ".tmp", 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) static void op_entry_remove_empty(void)
{ {
bool resave = false; 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 && while (resave == false &&
rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz) 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_tmp);
rb->close(fd_dat); rb->close(fd_dat);
fd_dat = -1;
rb->remove(OPEN_PLUGIN_DAT); rb->remove(OPEN_PLUGIN_DAT);
rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT); rb->rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
} }