> Bash version: 4.2.042 
> 
> I have a script that behaves erratically:

Thanks for the report.  The reason it is erratic and not always
reproducible in the same spot is that it is the result of an array
bounds error, and so depends on the contents of memory beyond the
end of a string.

I've fixed the problem, and the fix will be in the next release.  If
you're interested in the fix, I've attached a patch.

Chet

*** ../bash-4.2-patched/lib/glob/xmbsrtowcs.c   2012-07-08 21:53:19.000000000 
-0400
--- lib/glob/xmbsrtowcs.c       2013-02-12 12:00:39.000000000 -0500
***************
*** 217,220 ****
--- 217,226 ----
        n = mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
  
+       if (n == 0 && p == 0)
+       {
+         wsbuf[wcnum] = L'\0';
+         break;
+       }
+ 
        /* Compensate for taking single byte on wcs conversion failure above. */
        if (wcslength == 1 && (n == 0 || n == (size_t)-1))
***************
*** 222,226 ****
          state = tmp_state;
          p = tmp_p;
!         wsbuf[wcnum++] = *p++;
        }
        else
--- 228,238 ----
          state = tmp_state;
          p = tmp_p;
!         wsbuf[wcnum] = *p;
!         if (*p == 0)
!           break;
!         else
!           {
!             wcnum++; p++;
!           }
        }
        else

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to