nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] bindings: disallow executing an external command wh


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] bindings: disallow executing an external command when in view mode
Date: Tue, 2 Apr 2019 20:35:21 +0200

Otherwise the user could simply do something like

  ^R^X  sed -i 's/a/surprise!/g' name-of-current-file  <Enter>

and the file being viewed would be modified anyway.
---
 src/global.c | 4 ++--
 src/rcfile.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/global.c b/src/global.c
index 3dd07882..41bea902 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1039,7 +1039,7 @@ void shortcut_init(void)
                N_("No Conversion"), WITHORSANS(convert_gist), TOGETHER, 
NOVIEW);
 
        /* Command execution is only available when not in restricted mode. */
-       if (!ISSET(RESTRICTED)) {
+       if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) {
                add_to_funcs(flip_execute, MINSERTFILE,
                        N_("Execute Command"), WITHORSANS(execute_gist), 
TOGETHER, NOVIEW);
 
@@ -1328,7 +1328,7 @@ void shortcut_init(void)
        add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0);
        /* Only when not in restricted mode, allow Appending, Prepending,
         * making backups, and executing a command. */
-       if (!ISSET(RESTRICTED)) {
+       if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) {
                add_to_sclist(MWRITEFILE, "M-A", 0, append_void, 0);
                add_to_sclist(MWRITEFILE, "M-P", 0, prepend_void, 0);
                add_to_sclist(MWRITEFILE, "M-B", 0, backup_file_void, 0);
diff --git a/src/rcfile.c b/src/rcfile.c
index 1df7e540..506dcbc5 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -462,7 +462,7 @@ void parse_binding(char *ptr, bool dobind)
        menu = menu & (is_universal(newsc->func) ? MMOST : mask);
 
        if (!menu) {
-               if (!ISSET(RESTRICTED))
+               if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE))
                        rcfile_error(N_("Function '%s' does not exist in menu 
'%s'"),
                                                                funcptr, 
menuptr);
                goto free_things;
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]