[BusyBox 0004414]: xargs in version 1.11.1 has incorrect default for -e option

bugs at busybox.net bugs at busybox.net
Mon Aug 4 21:32:03 UTC 2008


The following issue has been CLOSED 
====================================================================== 
http://busybox.net/bugs/view.php?id=4414 
====================================================================== 
Reported By:                Araneidae
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   4414
Category:                   Other
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     closed
Resolution:                 open
Fixed in Version:           
====================================================================== 
Date Submitted:             08-01-2008 00:06 PDT
Last Modified:              08-04-2008 14:32 PDT
====================================================================== 
Summary:                    xargs in version 1.11.1 has incorrect default for -e
option
Description: 
The (undocumented) -e option for xargs, used to define an argument to be
treated as end of input (sets eof_str), has two problems.

1. The default value is "_".  This means that by default an argument of _
will be treated as end of input.  This is not a nice surprise!

2. The argument is current marked as taking an option value -- which means
that I can't specify an empty string to be end of input, which would
actually be useful.

The patch I attach below fixes both these issues, but does have the
disadvantage of introducing an incompatible change in behaviour.  However,
the current behaviour is both broken and undocumented, so maybe this is
good.
====================================================================== 

---------------------------------------------------------------------- 
 vda - 08-03-08 12:10  
---------------------------------------------------------------------- 
> The patch I attach below fixes both these issues, but does have the
disadvantage of introducing an incompatible change in behaviour.

Well, we match what GNU xargs does:

# true | xargs -e | hexdump -vC
00000000  0a                                                |.|
00000001
# true | /usr/bin/xargs -e | hexdump -vC
00000000  0a                                                |.|
00000001
# /usr/bin/xargs --version
GNU xargs version 4.1.20

> However, the current behaviour is both broken and undocumented

It is documented in GNU xargs manpage.

The bug is that busybox "xargs -e" does not switch off EOF string
detection. Fix:

diff -d -urpN busybox.5/findutils/xargs.c busybox.6/findutils/xargs.c
--- busybox.5/findutils/xargs.c 2008-07-22 01:04:20.000000000 +0200
+++ busybox.6/findutils/xargs.c 2008-08-03 21:10:47.000000000 +0200
@@ -376,6 +376,8 @@ enum {
 int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int xargs_main(int argc, char **argv)
 {
+       static const char const_eof_str[] ALIGN1 = "_";
+
        char **args;
        int i, n;
        xlist_t *list = NULL;
@@ -385,7 +387,7 @@ int xargs_main(int argc, char **argv)
        int n_max_arg;
        size_t n_chars = 0;
        long orig_arg_max;
-       const char *eof_str = "_";
+       const char *eof_str = const_eof_str;
        unsigned opt;
        size_t n_max_chars;
 #if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
@@ -396,6 +398,10 @@ int xargs_main(int argc, char **argv)

        opt = getopt32(argv, OPTION_STR, &max_args, &max_chars,
&eof_str);

+       /* -e without optional param? */
+       if ((opt & OPT_EOF_STRING) && eof_str == const_eof_str)
+               eof_str = NULL;
+
        if (opt & OPT_ZEROTERM)
                USE_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args =
process0_stdin); 

---------------------------------------------------------------------- 
 Araneidae - 08-03-08 15:09  
---------------------------------------------------------------------- 
> Well, we match what GNU xargs does:

Well, that's odd.  From Debian xargs(1):

       -Eeof-str
              Set  the  end of file string to eof-str.  If the end of file
string occurs as a
              line of input, the rest of the input is ignored.  If neither
-E nor -e is used,
              no end of file string is used.

       --eof[=eof-str], -e[eof-str]
              This  option is a synonym for the ‘-E’ option.  Use ‘-E’
instead, because it is
              POSIX compliant while this option is not.  If eof-str is
omitted, there  is  no
              end  of  file  string.   If neither -E nor -e is used, no
end of file string is
              used.

Well, you've demonstrated in the test that xargs (rather futilely) allows
-e to be specified with no string (alas, this means that an empty string
cannot be specified as eof, which actually could be useful). 
Interestingly, reading that man page at face value, I can specify -E'' or
--eof='' to specify an empty eof string (yes, I know '' expands to
nothing), so it's just the -e (non Posix) which is odd.

However, I can't see any evidence that the default eof string is _, and
the man page I've quoted suggests that the default should be NULL --
that's how I interpret "no end of file string is used".

So if we remove the "_" default this const_eof_str to be lost, which can't
be a bad thing.

To test: we current have

# echo $'one\n_\ntwo' | xargs
one

and I suggest (unless there's some other implementation we'll take as
reference) that we should see

# echo $'one\n_\ntwo' | xargs
one
_
two 

---------------------------------------------------------------------- 
 vda - 08-03-08 15:20  
---------------------------------------------------------------------- 
> Well, that's odd. From Debian xargs(1):

There is no "debian xargs". What your "xargs --version" prints?

> Well, you've demonstrated in the test that xargs (rather futilely)
allows -e to be specified with no string (alas, this means that an empty
string cannot be specified as eof, which actually could be useful)

This is fixed now in svn. "xargs -e" with no param means "don't use any
EOF string" now.

> However, I can't see any evidence that the default eof string is _, and
the man page I've quoted suggests that the default should be NULL --
that's how I interpret "no end of file string is used".

My xargs' manpage does explicitly say that _ is a default EOF string. But
I may have somewhat dated GNU xargs here (as I said, it's 4.1.20).

 

---------------------------------------------------------------------- 
 Araneidae - 08-03-08 22:43  
---------------------------------------------------------------------- 
$ xargs --version
GNU xargs version 4.2.28 

---------------------------------------------------------------------- 
 bernhardf - 08-04-08 06:42  
---------------------------------------------------------------------- 
debian:
$ xargs --version
xargs (GNU findutils) 4.4.0
$ echo $'one\n_\ntwo' | xargs
one _ two

RHEL5:
$ xargs --version
GNU xargs version 4.2.27
$ echo $'one\n_\ntwo' | xargs
one _ two

RHAS4.4:
$ xargs --version
GNU xargs version 4.1.20
$ echo $'one\n_\ntwo' | xargs
one

SuSE-10.3:
$ xargs --version
GNU xargs version 4.2.31
$ echo $'one\n_\ntwo' | xargs
one _ two

so i'd go for the 4.4.0 behaviour, as suggested by vda. 

---------------------------------------------------------------------- 
 vda - 08-04-08 14:32  
---------------------------------------------------------------------- 
Fixed in svn: -e defaults to "no EOF string, SUS-mandated -E added. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
08-01-08 00:06  Araneidae      New Issue                                    
08-01-08 00:06  Araneidae      Status                   new => assigned     
08-01-08 00:06  Araneidae      Assigned To               => BusyBox         
08-01-08 00:07  Araneidae      Issue Monitored: Araneidae                    
08-03-08 12:10  vda            Note Added: 0010174                          
08-03-08 15:09  Araneidae      Note Added: 0010204                          
08-03-08 15:20  vda            Note Added: 0010214                          
08-03-08 15:20  vda            Note Edited: 0010214                         
08-03-08 22:43  Araneidae      Note Added: 0010234                          
08-04-08 06:42  bernhardf      Note Added: 0010244                          
08-04-08 14:32  vda            Status                   assigned => closed  
08-04-08 14:32  vda            Note Added: 0010254                          
======================================================================




More information about the busybox-cvs mailing list