tags 317516 + patch
thanks

Hi Gerrit,

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.

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.

Cheers,
Martin
--- 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

Reply via email to