Loading ...
Sorry, an error occurred while loading the content.
 

Reading undofiles

Expand Messages
  • Christian Brabandt
    Hi Bram, this is a question that come up with one of my plugins, that implements an :SudoWrite function. It basically does this using ... When writing the
    Message 1 of 4 , Dec 6, 2011
      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

      --
      You received this message from the "vim_dev" 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
    • Bram Moolenaar
      ... 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,
      Message 2 of 4 , Dec 6, 2011
        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.

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

        /// Bram Moolenaar -- Bram@... -- 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 ///

        --
        You received this message from the "vim_dev" 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
      • Christian Brabandt
        Hi Bram! ... 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
        Message 3 of 4 , Dec 6, 2011
          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

          --
          You received this message from the "vim_dev" 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
        • Bram Moolenaar
          ... 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
          Message 4 of 4 , Dec 8, 2011
            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:

            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.

            /// Bram Moolenaar -- Bram@... -- 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 ///

            --
            You received this message from the "vim_dev" 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
          Your message has been successfully submitted and would be delivered to recipients shortly.