Bug#891179: In nvi, you can only search for ascii and latin-1 strings

2018-02-22 Thread spagoveanu
Package: nvi
Version: 1.81.6-13
Severity: important
Tags: patch upstream

In nvi, it's impossible to search for a string containing any unicode char
whose code point is > 0xff.

Example:
=
[working under an utf-8 locale]
$ cat /tmp/a.txt
tatătata
țațățața
țâțățâța
$ nvi /tmp/a.txt
... displays the file correctly
[inside nvi]
/ț
Pattern not found
/ă
Pattern not found
s/ă/A/g
No match found
=

And ':set extended' won't fix it, either.

[without the proper keyboard support, you can enter those characters
by copy-pasting them from this message]

This seems to have been always broken, but the "fix" for #523934
(14private_regex_fixes.patch) only made it worse.

The following patch fixes the search issue, and does not bring back
the "potential overflow" mentioned in the comment. Notice that the
'-' operator has precedence over '&'.

diff --git a/regex/regcomp.c b/regex/regcomp.c
index 12ee513..095ab7a 100644
--- a/regex/regcomp.c
+++ b/regex/regcomp.c
@@ -300,7 +300,7 @@ p_ere(register struct parse *p, int stop)
  
/* character this ERE should end at */
 {
-   register char c;
+   register int c;
register sopno prevback;
register sopno prevfwd;
register sopno conc;
@@ -344,7 +344,7 @@ p_ere(register struct parse *p, int stop)
 static void
 p_ere_exp(register struct parse *p)
 {
-   register char c;
+   register int c;
register sopno pos;
register int count;
register int count2;
@@ -624,7 +624,7 @@ p_simp_re(register struct parse *p, int starordinary)
/* FALLTHROUGH */
default:
  /* ordinary(p, c &~ BACKSL); -- Fix potential overflow */
-   ordinary(p, c & 0xff);
+   ordinary(p, c & BACKSL - 1);
break;
}
 



Bug#891174: [PATCH] Fix for bug #497342: nvi keeps files open for writing, making their execution fail with ETXTBSY

2018-02-22 Thread spagoveanu
Package: nvi
Version: 1.81.6-13
Severity: important
Tags: patch upstream

[sorry for opening another bug report instead of replying to the bug log,
but replies to the bug log seem to go *completely* ignored by everybody;
just check the end of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=497342;
that virus/phishing message is there since more than a year!]

Opening the file read-only is enough for flock() -- please notice that
ep->fd is only used to keep the lock hot, that's not the descriptor that
is used for reading or writing data to the file.

--- nvi-1.81.6.orig/common/exf.c
+++ nvi-1.81.6/common/exf.c
@@ -408,7 +408,7 @@ postinit:
 * an error.
 */
if (rcv_name == NULL && ep->refcnt == 0) {
-   if ((ep->fd = open(oname, O_RDWR)) == -1)
+   if ((ep->fd = open(oname, O_RDONLY)) == -1)
goto no_lock;
 
switch (file_lock(sp, oname, >fcntl_fd, ep->fd, 1)) {