Hi Matthew,

> less(1) fails to write its buffer to pathnames with environment
> variables or the tilda home directory shortcut in them. The following
> patch corrects this by using the shell to glob filenames with lessecho
> instead of glob(3).

I don't like this.
It looks like the wrong approach in my eyes.

If you want to access ~ in a C program, do not spawn a shell
to do globbing.  Instead, use geteuid(3) and getpwuid(3).
If you want $HOME, use getenv(3).

Besides, i don't like the lessecho(1) utility at all.
It's no good that everybody implements his own version of echo(1),
and this one has really weird features and options.
I certainly don't want it in /usr/bin on my systems.

But i don't think that's a problem because we don't need this at all.
If i want to save or copy files, i use cp(1) or an editor,
not less(1).  And even if i ever end up in less(1) for whatever
reason and want to save a file, i can do it, i just need to type
out the path.

So i consider this an extremely ugly solution for a basically
non-existent problem, and i have not even started looking
whether this has any potential to make people trip over their
own feet.  It might, 'cause it looks needlessly complex,
and escaping stuff and passing stuff to the shell is often
quite prone to errors and vulnerabilities.

Yours,
  Ingo


> Reproduction instructions:
> $ echo hi | less
> hi
> [type "s~/newfile.txt"]
> Cannot write to "~/newfile.txt"  (press RETURN)
> 
> $ echo hi | less
> hi
> [type "s$HOME/ksh.patch"]
> Cannot write to "$HOME/ksh.patch"  (press RETURN)
> 
> Index: Makefile.in
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/Makefile.in,v
> retrieving revision 1.9
> diff -u Makefile.in
> --- Makefile.in       16 Apr 2003 19:10:09 -0000      1.9
> +++ Makefile.in       28 Mar 2010 03:11:52 -0000
> @@ -48,7 +48,7 @@
>       output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
>       tags.${O} ttyin.${O} version.${O}  @REGEX_O@
>  
> -all: less lesskey
> +all: less lesskey lessecho
>  
>  less: ${OBJ}
>       ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS}
> @@ -56,6 +56,9 @@
>  lesskey: lesskey.${O} version.${O}
>       ${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O}
>  
> +lessecho: lessecho.${O} version.${O}
> +     ${CC} ${LDFLAGS} -o $@ lessecho.${O} version.${O}
> +
>  ${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h 
>  
>  filename.${O}: ${srcdir}/filename.c
> @@ -67,6 +70,7 @@
>  install: all
>       ${INSTALL_PROGRAM} less ${bindir}/${binprefix}less
>       ${INSTALL_PROGRAM} lesskey ${bindir}/${binprefix}lesskey
> +     ${INSTALL_PROGRAM} lessecho ${bindir}/${binprefix}lessecho
>  
>  install-strip:
>       ${MAKE} INSTALL_PROGRAM='${INSTALL_PROGRAM} -s' install
> Index: lglob.h
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/lglob.h,v
> retrieving revision 1.3
> diff -u lglob.h
> --- lglob.h   22 Apr 2003 22:57:13 -0000      1.3
> +++ lglob.h   28 Mar 2010 03:12:12 -0000
> @@ -25,7 +25,9 @@
>  #include <glob.h>
>  
>  #define GLOB_FLAGS                   (GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE)
> +#if 0
>  #define      DECL_GLOB_LIST(list)            glob_t list;  int i;
> +#endif
>  #define      GLOB_LIST(filename,list)        
> glob(filename,GLOB_FLAGS,0,&list)
>  #define      GLOB_LIST_FAILED(list)          0
>  #define      SCAN_GLOB_LIST(list,p)          i = 0;  i < list.gl_pathc;  i++

Reply via email to