9

It doesn't happen as often as you'd think, but it happens occasionally, and I don't even own a cat.

Basically if you mash the number row or numpad and then happen to hit a keycombo that triggers a repeatable command, it is possible to inadvertently command Vim to perform a task several thousand, million, or even billion times. This easily gets out of control and may result in data loss.

So I wonder if there is a configuration or something in the source code we can change to serve as a sanity check to prevent this sort of DoS.

7
  • 4
    Just to be sure that I understand your question: you regularly type by mistake some sequence like 144477@@ or 99999. and you want to stop those executions when the number is too big? Am I right? (I have to ask because that seems a little bit weird to me, I never had this problem)
    – statox
    Jun 14 '15 at 7:48
  • 3
    Why not… pay attention on what you do?
    – romainl
    Jun 14 '15 at 12:20
  • 3
    @statox yes, that's right. romainl has a valid point too, but it seems irrelevant to the question. The question remains, and it may not be as "serious" as other questions, but a question it is nonetheless. I simply think that it makes sense to be able to specify an upper bound on this to prevent accidental denial-of-service. As for the suggestion about undolevels, yes that can be relevant if this overflows undo buffer as well, I hadn't considered it either. (A not so contrived example -- I have a 60% keyboard, the top border row is numbers. I pick it up with my hand. Forget to unplug it. etc.)
    – Steven Lu
    Jun 14 '15 at 18:29
  • 4
    You can use set showcmd to show the keys you've typed in the bottom-right corner. Jun 28 '15 at 16:40
  • 1
    @Carpetsmoker I think that would qualify as a "prompt to confirm" since it shows on the screen. I recommend adding it as an answer (probably along with how to add it as a default option in .vimrc, so the answer is fully self-contained.)
    – Wildcard
    Oct 13 '15 at 18:05
2

I find that you are usually able to interrupt the repetition process by sending a SIGINT (Ctrl+C). As long as some vimscript is not running a really long inner loop, there is no DoS concern.

See here for an example of a plugin may contain a function that loops depending on the entered number.

For almost all intents and purposes this issue here is a hypothetical one.

3
  • 4
    "this issue is a hypothetical one"... No, it isn't. I've had to work on SSH on my phone over 2G connections, where I have accidentally missed a keystroke or made multiple keystrokes while typing in anticipation, resulting in very similar situations (maybe not 99999, but smaller numbers yes).
    – muru
    Jun 15 '15 at 17:05
  • Cool, yeah a slow terminal emulator (depending on the amount of changing that vim is applying) can exacerbate problems by adding processing delay on the client side. Gotta get to Ctrl+C quickly!
    – Steven Lu
    Jun 15 '15 at 23:24
  • 1
    You can just use <Esc>, you don't need to use <C-c>. The difference is that <C-c> aborts whatever Vim is doing (such as running a function), and <Esc> doesn't. You almost never want to use <C-c> unless you want to "kill" something. Jun 28 '15 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.