Tuesday, March 28, 2017

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

diff --git a/runtime/macros/less.vim b/runtime/macros/less.vim
index 72b53f269..347c2b457 100644
--- a/runtime/macros/less.vim
+++ b/runtime/macros/less.vim
@@ -70,8 +70,8 @@ au VimEnter * set nomod
set noma

" Give help
-noremap h :call <SID>Help()<CR>
-map H h
+noremap <nowait> h :call <SID>Help()<CR>
+map <nowait> H h
fun! s:Help()
echo "<Space> One page forward b One page backward"
echo "d Half a page forward u Half a page backward"
@@ -84,20 +84,21 @@ fun! s:Help()
echo "\n"
echo ":n<Enter> Next file :p<Enter> Previous file"
echo "\n"
+ echo "F Toggle Folds r Redraw"
echo "q Quit v Edit file"
let i = input("Hit Enter to continue")
endfun

" Scroll one page forward
-noremap <script> <Space> :call <SID>NextPage()<CR><SID>L
-map <C-V> <Space>
-map f <Space>
-map <C-F> <Space>
-map <PageDown> <Space>
-map <kPageDown> <Space>
-map <S-Down> <Space>
-map z <Space>
-map <Esc><Space> <Space>
+noremap <nowait><script> <Space> :call <SID>NextPage()<CR><SID>L
+map <nowait> <C-V> <Space>
+map <nowait> f <Space>
+map <nowait> <C-F> <Space>
+map <nowait> <PageDown> <Space>
+map <nowait> <kPageDown> <Space>
+map <nowait> <S-Down> <Space>
+map <nowait> z <Space>
+map <nowait> <Esc><Space> <Space>
fun! s:NextPage()
if line(".") == line("$")
if argidx() + 1 >= argc()
@@ -112,103 +113,106 @@ fun! s:NextPage()
endfun

" Re-read file and page forward "tail -f"
-map F :e<CR>G<SID>L:sleep 1<CR>F
+map <nowait> F :e<CR>G<SID>L:sleep 1<CR>F

" Scroll half a page forward
-noremap <script> d <C-D><SID>L
-map <C-D> d
+noremap <nowait><script> d <C-D><SID>L
+map <nowait> <C-D> d

" Scroll one line forward
-noremap <script> <CR> <C-E><SID>L
-map <C-N> <CR>
-map e <CR>
-map <C-E> <CR>
-map j <CR>
-map <C-J> <CR>
-map <Down> <CR>
+noremap <nowait><script> <CR> <C-E><SID>L
+map <nowait> <C-N> <CR>
+map <nowait> e <CR>
+map <nowait> <C-E> <CR>
+map <nowait> j <CR>
+map <nowait> <C-J> <CR>
+map <nowait> <Down> <CR>

" Scroll one page backward
-noremap <script> b <C-B><SID>L
-map <C-B> b
-map <PageUp> b
-map <kPageUp> b
-map <S-Up> b
-map w b
-map <Esc>v b
+noremap <nowait><script> b <C-B><SID>L
+map <nowait> <C-B> b
+map <nowait> <PageUp> b
+map <nowait> <kPageUp> b
+map <nowait> <S-Up> b
+map <nowait> w b
+map <nowait> <Esc>v b

" Scroll half a page backward
-noremap <script> u <C-U><SID>L
-noremap <script> <C-U> <C-U><SID>L
+noremap <nowait><script> u <C-U><SID>L
+noremap <nowait><script> <C-U> <C-U><SID>L

" Scroll one line backward
-noremap <script> k <C-Y><SID>L
-map y k
-map <C-Y> k
-map <C-P> k
-map <C-K> k
-map <Up> k
+noremap <nowait><script> k <C-Y><SID>L
+map <nowait> y k
+map <nowait> <C-Y> k
+map <nowait> <C-P> k
+map <nowait> <C-K> k
+map <nowait> <Up> k

" Redraw
-noremap <script> r <C-L><SID>L
-noremap <script> <C-R> <C-L><SID>L
-noremap <script> R <C-L><SID>L
+noremap <nowait><script> r <C-L><SID>L
+noremap <nowait><script> <C-R> <C-L><SID>L
+noremap <nowait><script> R <C-L><SID>L

" Start of file
-noremap <script> g gg<SID>L
-map < g
-map <Esc>< g
-map <Home> g
-map <kHome> g
+noremap <nowait><script> g gg<SID>L
+map <nowait> < g
+map <nowait> <Esc>< g
+map <nowait> <Home> g
+map <nowait> <kHome> g

" End of file
-noremap <script> G G<SID>L
-map > G
-map <Esc>> G
-map <End> G
-map <kEnd> G
+noremap <nowait><script> G G<SID>L
+map <nowait> > G
+map <nowait> <Esc>> G
+map <nowait> <End> G
+map <nowait> <kEnd> G

" Go to percentage
-noremap <script> % %<SID>L
-map p %
+noremap <nowait><script> % %<SID>L
+map <nowait> p %

" Search
-noremap <script> / H$:call <SID>Forward()<CR>/
+noremap <nowait><script> / H$:call <SID>Forward()<CR>/
if &wrap
- noremap <script> ? H0:call <SID>Backward()<CR>?
+ noremap <nowait><script> ? H0:call <SID>Backward()<CR>?
else
- noremap <script> ? Hg0:call <SID>Backward()<CR>?
+ noremap <nowait><script> ? Hg0:call <SID>Backward()<CR>?
endif

fun! s:Forward()
" Searching forward
- noremap <script> n H$nzt<SID>L
+ noremap <nowait><script> n H$nzt<SID>L
if &wrap
- noremap <script> N H0Nzt<SID>L
+ noremap <nowait><script> N H0Nzt<SID>L
else
- noremap <script> N Hg0Nzt<SID>L
+ noremap <nowait><script> N Hg0Nzt<SID>L
endif
- cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
+ cnoremap <nowait><silent><script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
endfun

fun! s:Backward()
" Searching backward
if &wrap
- noremap <script> n H0nzt<SID>L
+ noremap <nowait><script> n H0nzt<SID>L
else
- noremap <script> n Hg0nzt<SID>L
+ noremap <nowait><script> n Hg0nzt<SID>L
endif
- noremap <script> N H$Nzt<SID>L
- cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
+ noremap <nowait><script> N H$Nzt<SID>L
+ cnoremap <nowait><silent><script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L
endfun

call s:Forward()
-cunmap <CR>
+cunmap <nowait> <CR>

" Quitting
-noremap q :q<CR>
+noremap <nowait> q :q<CR>
+
+" Toggle folding
+noremap <script><nowait> F zi<SID>L

" Switch to editing (switch off less mode)
-map v :silent call <SID>End()<CR>
+map <nowait><silent> v :silent call <SID>End()<CR>
fun! s:End()
set ma
if exists('s:lz')
On Mo, 27 Mär 2017, L. A. Walsh wrote:

> Ken Takata wrote:
> >Hi,
> >
> >2017/3/28 Tue 6:19:19 UTC+9 L A Walsh wrote:
> >>If I have a file with folds in it (fdm=marker), and I try to
> >>display it with the vim 'less.sh' script, there doesn't seem to be
> >>a way to get rid of all the folds (no 'zR'). I can use the cursor
> >>keys to move to each fold and open it, but that really defeats
> >>the idea of using 'less' to scroll through the source by pressing
> >>'space' (for example).
> >>
> >>Maybe folds should be disabled for the less.sh script?
> >
> >I'm not sure it should be disabled. However, you can use the following
> >command as a workaround to open all folds:
> >
> > :norm! zR
> ----
> Thanks for the workaround, but where do I put that to
> make it default, in the the less.vim file?

You can also use zi or :set nofoldenable or something like this.

> Why would you think it shouldn't be disabled? I.e.
> how does it help emulate the file-pagers 'less' or 'more' while
> providing syntax-coloring?

Because less.vim does what Vim would do.

> From a different perspective, how would a non-vim user
> know what to do to use 'less.sh' if it is supposed to be a pager
> like 'less' or 'more' to page through file or program text without
> having various portions of files possibly hidden.

How likely is it, that a non-vim user gets into contact with less.vim?

> It seems that if anyone was using less.sh to display files,
> as they would 'less' or 'more' (but w/syntax highlighting), then
> having text being hidden would seem to be a potential security
> risk, no?

Where do you see a security risk? It is pretty obvious, that a fold is
there, so it should be easy to disable it and then you see what is
hidden behind a fold.

How about the attached patch?

@Bram,
please see the attached patch. It improves less.vim in several ways:

- Makes 'F' toggle folds to make it easier to disable folds and also
displays it in the help overview
- Display 'r' key in the help overview
- Add <nowait> to the mappings, because when trying out less.vim
I found quite a few of the keys where not working as expected, since
many plugins map the same keys (or the same prefix, which make Vim
wait until the timeout triggers)

On a related note, I see that less.bat and less.sh set 'no_plugin_maps'
However only 11 of over 200 filetype plugins actually check that
variable. I suggest to at least add a help tag *no_plugin_maps* to
encourage filetype plugin writers to respect that variable.

Best,
Christian
--
Das Glück ist eine leichtfertige Person, die sich stark schminkt und
von ferne schön ist.
-- Johann Nepomuk Nestroy

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment