From f9c5d1fccf2b82b2f1eb6c3e525643e9d3ba6264 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 29 Jul 2021 23:13:20 -0400 Subject: [PATCH] open_plugin.c (CORE) File input Bugfixes Explicitly Null terminate char fields 0 is a valid file descriptor Change-Id: I0faa9f5ec919ca913bceabf919fbaefcb38c39b9 --- apps/open_plugin.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/open_plugin.c b/apps/open_plugin.c index c64661f2e6..8453b3976d 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c @@ -60,12 +60,12 @@ static int op_update_dat(struct open_plugin_entry_t *entry) hash = entry->hash; fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (!fd) + if (fd < 0) return -1; write(fd, entry, op_entry_sz); fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); - if (fd1) + if (fd1 >= 0) { while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) { @@ -189,13 +189,18 @@ static int open_plugin_hash_get_entry(uint32_t hash, int fd = open(dat_file, O_RDONLY); - if (fd) + if (fd >= 0) { while (read(fd, entry, op_entry_sz) == op_entry_sz) { record++; if (hash == 0 || entry->hash == hash) { + /* NULL terminate fields NOTE -- all are actually +1 larger */ + entry->name[OPEN_PLUGIN_NAMESZ] = '\0'; + /*entry->key[OPEN_PLUGIN_BUFSZ] = '\0';*/ + entry->path[OPEN_PLUGIN_BUFSZ] = '\0'; + entry->param[OPEN_PLUGIN_BUFSZ] = '\0'; ret = record; break; }