Reading undofiles

24 views
Skip to first unread message

Christian Brabandt

unread,
Dec 6, 2011, 2:22:01 PM12/6/11
to vim...@vim.org
Hi Bram,
this is a question that come up with one of my plugins, that implements
an :SudoWrite function. It basically does this using
:%w !tee > /dev/null buffername

When writing the buffer the owner of that file and the undofile have
different owners and this prevents Vim from reading in the undofile when
starting up.

But, I still can successfully use :rundo undofile(@%) and Vim will
happily use that undofile even so the ownership differs.

This seems to contradict the intention of using the undofiles. Why does
Vim only check the permissions when not given an explicit filename but
doesn't care, when a file name is given?

regards,
Christian

Bram Moolenaar

unread,
Dec 6, 2011, 3:37:42 PM12/6/11
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

Trojan horse. Vim must not use a file from a different owner without
the user explicitly telling Vim to do so. Vim would also never create
such a file, thus it's most likely because someone else edited the file,
in which case the undo information is not to be used. Or the file name
was mixed up. But if the user uses :rundo he probably knows what he is
doing.

--
"Women marry men hoping they will change. Men marry women hoping
they will not. So each is inevitably disappointed."
- Einstein

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Dec 6, 2011, 4:25:51 PM12/6/11
to vim...@vim.org
Hi Bram!

On Di, 06 Dez 2011, Bram Moolenaar wrote:

>
> Christian Brabandt wrote:
>
> > this is a question that come up with one of my plugins, that implements
> > an :SudoWrite function. It basically does this using
> > :%w !tee > /dev/null buffername
> >
> > When writing the buffer the owner of that file and the undofile have
> > different owners and this prevents Vim from reading in the undofile when
> > starting up.
> >
> > But, I still can successfully use :rundo undofile(@%) and Vim will
> > happily use that undofile even so the ownership differs.
> >
> > This seems to contradict the intention of using the undofiles. Why does
> > Vim only check the permissions when not given an explicit filename but
> > doesn't care, when a file name is given?
>
> Trojan horse. Vim must not use a file from a different owner without
> the user explicitly telling Vim to do so. Vim would also never create
> such a file, thus it's most likely because someone else edited the file,
> in which case the undo information is not to be used. Or the file name
> was mixed up. But if the user uses :rundo he probably knows what he is
> doing.

Well fair enough. But since undofiles are checksummed, there shouldn't
be a problem there.

BTW: I found a minor bug, that is when using :wundo the checksum that
will be calculated will be wrong, since u_compute_hash only iterates
over all lines except the last. That makes u_read_undo fail silently
when starting. Unfortunately, using :rundo filename will still work,
(since it also used u_compute_hash), which made it hard to find the
error.

Please check and include:

diff --git a/src/undo.c b/src/undo.c
--- a/src/undo.c
+++ b/src/undo.c
@@ -719,7 +719,7 @@
char_u *p;

sha256_start(&ctx);
- for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum)
+ for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
{
p = ml_get(lnum);
sha256_update(&ctx, p, (UINT32_T)(STRLEN(p) + 1));


regards,
Christian

Bram Moolenaar

unread,
Dec 8, 2011, 8:21:30 AM12/8/11
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

Good catch! Strange that this wasn't detected before. I'll include the
patch, thanks.

--
hundred-and-one symptoms of being an internet addict:
245. You use Real Audio to listen to a radio station from a distant
city rather than turn on your stereo system.

Reply all
Reply to author
Forward
0 new messages