On 2009/06/03 13:33, Nicholas Marriott wrote:
> CVSROOT:      /cvs
> Module name:  src
> Changes by:   n...@cvs.openbsd.org    2009/06/03 13:33:04
> 
> Modified files:
>       usr.bin/tmux   : input.c screen.c 
> 
> Log message:
> Pass window titles through vis(1). <0x20 is dropped anyway by the input state
> machine but top-bit-set nonprintables could cause trouble, and they are neater
> like this anyway.

ah, reminds me of this M that's been annoying me.
ok? or shall I drop it?


----- Forwarded message from Stuart Henderson <s...@spacehopper.org> -----

From: Stuart Henderson <s...@spacehopper.org>
Date: Fri, 24 Apr 2009 17:58:50 +0100
To: t...@openbsd.org
User-Agent: Mutt/1.5.19 (2009-01-05)
Subject: Re: diff -p; run function names through strnvis()

On 2009/04/24 17:25, Stuart Henderson wrote:
> I noticed when making a patch for something I'm porting which includes
> escape sequences for colours in the source code (stop sniggering at the
> back...) with -p (as normally set in "make update-patches" in the ports
> tree) that it picked up one such line as a function name, so it included
> the escape char in the diff.
> 
> It seems saner to run function names through strnvis as in the diff
> below, though I still wonder if asciifile() should really treat these
> as ascii (though changing that behaviour is more likely to cause
> problems for other software).
> 
> Any comments?

xsa@ pointed me at the internal copies in rcs/cvs, so here's an updated
diff with all three.

Index: cvs/diff_internals.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/diff_internals.c,v
retrieving revision 1.25
diff -N -u -p cvs/diff_internals.c
--- cvs/diff_internals.c        11 Jun 2008 03:38:28 -0000      1.25
+++ cvs/diff_internals.c        24 Apr 2009 16:57:13 -0000
@@ -75,6 +75,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "cvs.h"
 #include "diff.h"
@@ -1218,6 +1219,7 @@ static char *
 match_function(const long *f, int pos, FILE *fp)
 {
        unsigned char buf[FUNCTION_CONTEXT_SIZE];
+       unsigned char rawbuf[FUNCTION_CONTEXT_SIZE];
        size_t nc;
        int last = lastline;
        char *p;
@@ -1227,12 +1229,13 @@ match_function(const long *f, int pos, FILE *fp)
        while (pos > last) {
                fseek(fp, f[pos - 1], SEEK_SET);
                nc = f[pos] - f[pos - 1];
-               if (nc >= sizeof(buf))
-                       nc = sizeof(buf) - 1;
-               nc = fread(buf, 1, nc, fp);
+               if (nc >= sizeof(rawbuf))
+                       nc = sizeof(rawbuf) - 1;
+               nc = fread(rawbuf, 1, nc, fp);
                if (nc > 0) {
-                       buf[nc] = '\0';
-                       p = strchr((const char *)buf, '\n');
+                       rawbuf[nc] = '\0';
+                       p = strchr((const char *)rawbuf, '\n');
+                       strnvis(buf, rawbuf, sizeof(buf), VIS_SAFE|VIS_NOSLASH);
                        if (p != NULL)
                                *p = '\0';
                        if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
Index: diff/diffreg.c
===================================================================
RCS file: /cvs/src/usr.bin/diff/diffreg.c,v
retrieving revision 1.70
diff -N -u -p diff/diffreg.c
--- diff/diffreg.c      11 Sep 2007 15:47:17 -0000      1.70
+++ diff/diffreg.c      24 Apr 2009 16:57:13 -0000
@@ -81,6 +81,7 @@ static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.7
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "diff.h"
 #include "pathnames.h"
@@ -1298,6 +1299,7 @@ static char *
 match_function(const long *f, int pos, FILE *file)
 {
        unsigned char buf[FUNCTION_CONTEXT_SIZE];
+       unsigned char rawbuf[FUNCTION_CONTEXT_SIZE];
        size_t nc;
        int last = lastline;
        char *state = NULL;
@@ -1306,12 +1308,13 @@ match_function(const long *f, int pos, FILE *file)
        while (pos > last) {
                fseek(file, f[pos - 1], SEEK_SET);
                nc = f[pos] - f[pos - 1];
-               if (nc >= sizeof(buf))
-                       nc = sizeof(buf) - 1;
-               nc = fread(buf, 1, nc, file);
+               if (nc >= sizeof(rawbuf))
+                       nc = sizeof(rawbuf) - 1;
+               nc = fread(rawbuf, 1, nc, file);
                if (nc > 0) {
-                       buf[nc] = '\0';
-                       buf[strcspn(buf, "\n")] = '\0';
+                       rawbuf[nc] = '\0';
+                       rawbuf[strcspn(rawbuf, "\n")] = '\0';
+                       strnvis(buf, rawbuf, sizeof(buf), VIS_SAFE|VIS_NOSLASH);
 
                        if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
                                if (begins_with(buf, "private:")) {
Index: rcs/diff.c
===================================================================
RCS file: /cvs/src/usr.bin/rcs/diff.c,v
retrieving revision 1.25
diff -N -u -p rcs/diff.c
--- rcs/diff.c  11 Sep 2007 15:47:17 -0000      1.25
+++ rcs/diff.c  24 Apr 2009 16:57:13 -0000
@@ -75,6 +75,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "buf.h"
 #include "diff.h"
@@ -1153,6 +1154,7 @@ static char *
 match_function(const long *f, int pos, FILE *fp)
 {
        unsigned char buf[FUNCTION_CONTEXT_SIZE];
+       unsigned char rawbuf[FUNCTION_CONTEXT_SIZE];
        size_t nc;
        int last = lastline;
        char *state = NULL;
@@ -1161,13 +1163,13 @@ match_function(const long *f, int pos, FILE *fp)
        while (pos > last) {
                fseek(fp, f[pos - 1], SEEK_SET);
                nc = f[pos] - f[pos - 1];
-               if (nc >= sizeof(buf))
-                       nc = sizeof(buf) - 1;
-               nc = fread(buf, 1, nc, fp);
+               if (nc >= sizeof(rawbuf))
+                       nc = sizeof(rawbuf) - 1;
+               nc = fread(rawbuf, 1, nc, fp);
                if (nc > 0) {
-                       buf[nc] = '\0';
-
-                       buf[strcspn(buf, "\n")] = '\0';
+                       rawbuf[nc] = '\0';
+                       rawbuf[strcspn(rawbuf, "\n")] = '\0';
+                       strnvis(buf, rawbuf, sizeof(buf), VIS_SAFE|VIS_NOSLASH);
 
                        if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') {
                                if (begins_with(buf, "private:")) {


----- End forwarded message -----

Reply via email to