On Sun, Mar 31, 2013 at 08:49:03PM +0100, Stuart Henderson wrote:
> On 2013/03/31 16:46, Marc Espie wrote:
> > On Sun, Mar 31, 2013 at 04:32:05PM +0200, Marc Espie wrote:
> > > On Sun, Mar 31, 2013 at 03:26:56PM +0100, Stuart Henderson wrote:
> > > > On 2013/03/31 16:17, Marc Espie wrote:
> > > > > +diff -uNp
> > > > 
> > > > oh, and there is one thing about -p as a default: it increases
> > > > the chances of a messed-up terminal if the file has binary crap in
> > > > it, as it does not do any strnvis() or similar.
> > > 
> > > We could (should) fix that. That's rather trivial to do...
> > 
> > Actually, no. It makes little sense. The diff itself doesn't encode its
> > input.  
> > 
> > The function name that -p outputs is just as dangerous as the source file
> > contents itself...
> > 
> 
> You know what you're going to get if you edit a line with/near
> lines like this and then diff it, but the function name can be a bit
> unexpected (I had minor trouble with this in the past with update-patches
> in ports). Not particularly major, just thought it worth mentioning if
> we're talking about adding this to default config.

If it's really a valid concern, as far as I can tell, It's just a question of

Index: usr.bin/diff/diffreg.c
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/diff/diffreg.c,v
retrieving revision 1.82
diff -u -p -r1.82 diffreg.c
--- usr.bin/diff/diffreg.c      8 Jul 2012 15:48:56 -0000       1.82
+++ usr.bin/diff/diffreg.c      31 Mar 2013 14:43:18 -0000
@@ -77,6 +77,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "diff.h"
 #include "pathnames.h"
@@ -1329,7 +1330,8 @@ match_function(const long *f, int pos, F
                                        if (!state)
                                                state = " (public)";
                                } else {
-                                       strlcpy(lastbuf, buf, sizeof lastbuf);
+                                       strnvis(lastbuf, buf, sizeof lastbuf,
+                                           VIS_SAFE);
                                        if (state)
                                                strlcat(lastbuf, state,
                                                    sizeof lastbuf);
Index: usr.bin/rcs/diff.c
===================================================================
RCS file: /home/openbsd/cvs/src/usr.bin/rcs/diff.c,v
retrieving revision 1.33
diff -u -p -r1.33 diff.c
--- usr.bin/rcs/diff.c  20 Apr 2011 19:34:16 -0000      1.33
+++ usr.bin/rcs/diff.c  31 Mar 2013 14:44:28 -0000
@@ -72,8 +72,10 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <vis.h>
 
 #include "buf.h"
 #include "diff.h"
@@ -1176,10 +1178,8 @@ match_function(const long *f, int pos, F
                                        if (!state)
                                                state = " (public)";
                                } else {
-                                       if (strlcpy(lastbuf, buf,
-                                           sizeof(lastbuf)) >= sizeof(lastbuf))
-                                               errx(1,
-                                                   "match_function: strlcpy");
+                                       strnvis(lastbuf, buf, sizeof(lastbuf), 
+                                           VIS_SAFE);
                                        lastmatchline = pos;
                                        return lastbuf;
                                }

Reply via email to