forwarded 317516 upstream quit Hi Martin,
On Sat, Sep 03, 2005 at 02:56:00PM +0200, Martin Dickopp wrote: > When analysing the bug I came to the following conclusion: The loop > beginning at input.c:302 overwrites a single input line with itself, > skipping NUL characters. Therefore, after the loop the line buffer > has less characters than originally read if and only if the input line > contains NUL characters. yes. Thanks a lot for the details and patch. > The pointer that is used to read from the buffer, 'parsenextc' (cf. > input.h:66), is also used as the beginning of the next line in > input.c:296. This fails if the buffer contains less characters > than originally read into it due to NUL characters. > > The proposed patch (attached) keeps track of the number of skipped > characters and advances 'parsenextc' accordingly before processing > the next input line. Hi Herbert, please see http://bugs.debian.org/317516 Martin's patch fixes the problem in the parser, but has issues with the -x switch, here are some test cases. Without the patch: $ printf '\0: 0123456789\n: 0123456789\n: 0123456789\n' |dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf '\0\0: 0123456789\n: 0123456789\n: 0123456789\n' |dash -x + : 0123456789 + 9 dash: 9: not found + : 0123456789 + : 012345678 $ printf '\0\0\0: 0123456789\n: 0123456789\n: 0123456789\n' |dash -x + : 0123456789 + 89 dash: 89: not found + : 0123456789 + : 01234567 $ printf ': 0123456789\0\0\0\n: 0123456789\n: 0123456789\n' |dash -x + : 0123456789 + : 0123456789 + : 01234 $ printf ': 0123456789\n\0: 0123456789\n: 0123456789\n' |dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf ': 0123456789\n\0: 01\023456789\n: 0123456789\n' |dash -x + : 0123456789 + : 01456789 + : 0123456789 $ printf ': 0123456789\n\0\0: 01\023456789\n: 0123456789\n' |dash -x + : 0123456789 + : 01456789 + 9 dash: 9: not found + : 012345678 $ printf ': 0123456789\n\0\0: 01\02\0345\06789\n: 0123456789\n' |dash -x + : 0123456789 + : 015789 + 9 dash: 9: not found + : 012345678 $ With the patch: $ printf '\0: 0123456789\n: 0123456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf '\0\0: 0123456789\n: 0123456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf '\0\0\0: 0123456789\n: 0123456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf ': 0123456789\0\0\0\n: 0123456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf ': 0123456789\n\0: 0123456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 0123456789 + : 0123456789 $ printf ': 0123456789\n\0: 01\023456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 01456789 + : 0123456789 $ printf ': 0123456789\n\0\0: 01\023456789\n: 0123456789\n' |./dash -x + : 0123456789 + : 01456789 + : 0123456789 $ printf ': 0123456789\n\0\0: 01\02\0345\06789\n: 0123456789\n' |./dash -x + : 0123456789 + : 015789 + : 0123456789 $ Thanks, Gerrit. > --- dash-0.5.2.ORIG/src/input.c 2003-03-08 03:43:47.000000000 +0100 > +++ dash-0.5.2/src/input.c 2005-09-03 14:22:23.000000000 +0200 > @@ -266,6 +266,7 @@ > int something; > #endif > char savec; > + static size_t skipped_characters = 0; > > while (parsefile->strpush) { > if ( > @@ -285,6 +286,9 @@ > flushout(&errout); > #endif > > + parsenextc += skipped_characters; > + skipped_characters = 0; > + > again: > if (parselleft <= 0) { > if ((parselleft = preadfd()) <= 0) { > @@ -303,6 +307,7 @@ > switch (*p) { > case '\0': > p++; /* Skip nul */ > + skipped_characters++; > goto check; > > #ifndef SMALL -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]