netstar pushed a commit to branch master. http://git.enlightenment.org/apps/ecrire.git/commit/?id=e5cf942255ca75907c851bd4eb8c8744faf615bf
commit e5cf942255ca75907c851bd4eb8c8744faf615bf Author: Alastair Poole <nets...@gmail.com> Date: Sat Feb 27 11:39:45 2021 +0000 ecrire: arguent load defense --- src/bin/file_utils.c | 7 +++++++ src/bin/main.c | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bin/file_utils.c b/src/bin/file_utils.c index 8b97112..8289be7 100644 --- a/src/bin/file_utils.c +++ b/src/bin/file_utils.c @@ -26,11 +26,18 @@ file_load(const char *file) { FILE *f; size_t size; + struct stat st; int alloc = 0, len = 0; char *text = NULL, buf[16384 + 1]; + if (stat(file, &st) != -1) + { + if (st.st_size == 0) return strdup(""); + } + f = fopen(file, "rb"); if (!f) return NULL; + while ((size = fread(buf, 1, sizeof(buf) - 1, f))) { char *tmp_text; diff --git a/src/bin/main.c b/src/bin/main.c index 9f7ae21..bc76c30 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -344,11 +344,11 @@ _load_to_entry(Ecrire_Entry *inst, const char *file) char *buf; if (plain_utf8) - buf = file_plain_load(file); + buf = file_plain_load(file); else - buf = file_load(file); + buf = file_load(file); - if (!buf) + if (!buf) ok = 0; else { @@ -357,7 +357,7 @@ _load_to_entry(Ecrire_Entry *inst, const char *file) elm_entry_entry_append(inst->entry, buf); elm_object_item_disabled_set(inst->save_item, EINA_TRUE); free(buf); - } + } } if (ok) @@ -718,7 +718,15 @@ elm_main(int argc, char **argv) if (optind < argc) { - inst->filename = eina_stringshare_add(argv[optind]); + if (!ecore_file_exists(argv[optind])) + return 1; + char *path = ecore_file_realpath(argv[optind]); + if (path) + { + if (ecore_file_is_dir(argv[optind])) return 1; + + inst->filename = eina_stringshare_add(path); + } } DBG("Opening filename: '%s'", inst->filename); @@ -789,6 +797,7 @@ elm_main(int argc, char **argv) elm_run(); + eina_stringshare_del(inst->filename); free(inst); ecrire_cfg_shutdown(); --