[PATCH] Fix infinite loop in x_zots (edit.c)

2014-07-05 Thread Ivan Delalande
Hi,

In rare occasions, when invalid UTF-8 sequences are present in the
command line buffer, the loop in x_zots() loops indefinitely because we
have str  xlp and x_col == xx_cols, so the condition for the loop
will be true, but the actual code that increments the str pointer in
the x_e_putc2 and x_e_putc3 functions is protected by the condition
x_col  xx_cols which is false, and so the pointer remains at the
same value indefinitely.

This patch only fixes the infinite loop problem, not the fondamental
problem of invalid UTF-8 sequences handling. This would really be nice
to have something consistent there because the command line prompt
really goes nuts when such sequences are present.

Thank you,
-- 
Ivan Colona Delalande
Index: edit.c
===
RCS file: /cvs/src/bin/mksh/edit.c,v
retrieving revision 1.275
diff -u -r1.275 edit.c
--- edit.c	5 Jan 2014 21:57:48 -	1.275
+++ edit.c	5 Jul 2014 19:55:10 -
@@ -1628,7 +1628,7 @@
 	int adj = x_adj_done;
 
 	x_lastcp();
-	while (*str  str  xlp  adj == x_adj_done)
+	while (*str  str  xlp  x_col  xx_cols  adj == x_adj_done)
 		x_zotc3(str);
 }
 


Re: [PATCH] Fix infinite loop in x_zots (edit.c)

2014-07-05 Thread Thorsten Glaser
Ivan Delalande dixit:

In rare occasions, when invalid UTF-8 sequences are present in the
command line buffer, the loop in x_zots() loops indefinitely because we
have str  xlp and x_col == xx_cols, so the condition for the loop

Ouch. Thanks for noticing.

will be true, but the actual code that increments the str pointer in
the x_e_putc2 and x_e_putc3 functions is protected by the condition
x_col  xx_cols which is false, and so the pointer remains at the
same value indefinitely.

OK, will look at it. Thanks!

This patch only fixes the infinite loop problem, not the fondamental
problem of invalid UTF-8 sequences handling. This would really be nice
to have something consistent there because the command line prompt
really goes nuts when such sequences are present.

Indeed. I’ve got (long-term) plans for rewriting the entire edit
thing using wide character arrays (tbh, probably, the entire string
handling in the shell, lexer, parser, etc) and killing the current
Vi mode (possibly making a new one reusing Emacs mode functionality).
But that’s still a few months or years into the future :(

I think the current editing mode works well enough with UTF-8, which
everyone “sane” uses, and will focus on the shell programming language
first.

Nevertheless, thank you a lot for caring! Known bugs should be fixed
after all.

bye,
//mirabilos
-- 
[00:02] Vutral gecko: benutzt du emacs ?
[00:03] gecko nö  [00:03] gecko nur n normalen mac
[00:04] Vutral argl   [00:04] Vutral ne den editor
-- Vutral und gecko2 in #deutsch (NB: Editor? Betriebssystem.)