delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/04/15/23:48:09

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <480576DA.5070106@cwilson.fastmail.fm>
Date: Tue, 15 Apr 2008 23:47:38 -0400
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080213 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: [Attn: alternatives maintainer] - ghostscript preremove breakage
References: <7zk5j0yt70 DOT fsf AT vzell-de DOT de DOT oracle DOT com> <4803E1B3 DOT 8070809 AT cwilson DOT fastmail DOT fm> <7zbq4ct3wv DOT fsf AT vzell-de DOT de DOT oracle DOT com> <48040493 DOT 7010205 AT cwilson DOT fastmail DOT fm> <7zprsrqfzm DOT fsf AT vzell-de DOT de DOT oracle DOT com>
In-Reply-To: <7zprsrqfzm.fsf@vzell-de.de.oracle.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Dr. Volker Zell wrote:
> This is the relevant code block in alternatives.c where the above file 
> gets read by the function readConfig (buf should hold the contents of the above file 
> after the do loop):
> 
> 
>     curBufSz = READCONFIG_BUF_INITIALSZ;
>     totalBytesRead = 0;
>     numBytesRead = 0;
>     buf = NULL;
>     do
>     {
>        if (curBufSz < READCONFIG_BUF_BEHAVIOR_THRESH)
>           curBufSz *= 2;
>        else
>           curBufSz += READCONFIG_BUF_BEHAVIOR_THRESH;
> 
>        buf = realloc(buf, curBufSz + 1);
> 
>        bufp = buf + totalBytesRead;

try putting
	*bufp = '\0';
right here.

>        numBytesRead = read(fd, bufp, curBufSz - totalBytesRead);
> 
>        /* don't add '-1' ! */
>        if (numBytesRead > 0)
>            totalBytesRead += numBytesRead;
>     }
>     while (numBytesRead > 0);



> 
> (gdb) p bufp
> $38 = 0x664a08 "1\n20\nµ"

Whoa. That is odd. I wonder if it's an uninitialized memory thing -- 
realloc does not zero out the "new" storage; it only copies over the old 
storage up to the old storage's length.

> (gdb) p buf
> $39 = 0x6649e8 "auto\n/usr/bin/gs\n\n/usr/bin/gs-x11\n20\nµ"
> 
> and then later on in parseLine after a while:
> 
> bufp=µ
> 
> and boom...

Yep, that would do it.

> It looks like something went wrong in line 219
> 
> numBytesRead = read(fd, bufp, curBufSz - totalBytesRead);
> 
> Also numBytesRead=5, bufp="1\n20\nµ" instead of "1\n20\n"
> 
> 
> I have no idea where the µ comes from.
> 
> Running alternative on one of your packages is fine:

Memory issues are always tricky. If the fix above corrects the error, 
I've got to wonder how we've been so lucky on all the other packages 
that use the alternatives system...

--
Chuck


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019