chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Fix build on Vista and fix debugger host:port


From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Fix build on Vista and fix debugger host:port parsing
Date: Mon, 15 Feb 2016 21:34:58 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hello all,

In preparation of the 4.11, I'm doing some quick tests on various OSes.
When I built in Vista with MingW, it complained that strndup() isn't
defined.  Usually I'd argue this software is too old and yadda yadda,
but the one line in dbg-stub.c is the only thing preventing a succesful
build, so I think it's worth fixing.

The "fix" is to simply copy the entire string using strdup() (which is
much older) and replace the colon which separates host and port with a
NUL.  We could also use strlcpy(), but why bother in this case, as the
port shouldn't be very long anyway.

More importantly, I found out that the stop condition for the for()
loop which scans for a colon was slightly off: i >= 0 will mean after
the loop, i equals -1.  That means the if (i == 0) won't trigger like
it should.  Instead, it would drop into the else and copy the entire
host string (because strndup accepts a size_t, which is unsigned, the
-1 value of i would be cast to the largest possible unsigned value).

I'd say it should also allocate a huge chunk of memory, but I guess
that either doesn't happen because strndup() is too smart, or we're
just ignoring NULL results here anyway.

The attached fix stops looping *before* i overshoots 0.  That means
we're not checking whether add starts immediately with a colon, but
I think that's okay because then there'd be an empty host string.
There are probably smarter ways to do this, but it's getting late
here and at least this works: I tested that the client can connect
to feathers (only tested on Linux) and the Vista build now works too.

This patch applies to master _and_ chicken-5.

Cheers,
Peter

Attachment: 0001-Replace-strndup-with-strdup-for-compat-reasons.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]