]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
test: fix segfault in networkxml2argvtest
authorLaine Stump <laine@laine.org>
Thu, 5 Apr 2012 07:18:33 +0000 (03:18 -0400)
committerLaine Stump <laine@laine.org>
Thu, 5 Apr 2012 11:04:43 +0000 (07:04 -0400)
commitbde32b1ada0d0c8d9e3f82bebe19472b620ef54e
treefc544d54bc0eb4f77349b30518065d72a9bb27df
parent80d476a92ff0b5c2db00fdf37842757f45e30560
test: fix segfault in networkxml2argvtest

This bug resolves https://bugzilla.redhat.com/show_bug.cgi?id=810100

rpm builds for i686 were failing with a segfault in
networkxml2argvtest. Running under valgrind showed that a region of
memory was being referenced after it had been freed (as the result of
realloc - see the valgrind report in the BZ).

The problem (in replaceTokens() - added in commit 22ec60, meaning this
bug was in 0.9.10 and 0.9.11) was that the pointers token_start and
token_end were being computed based on the value of *buf, then *buf
was being realloc'ed (potentially moving it), then token_start and
token_end were used without recomputing them to account for movement
of *buf.

The solution is to change the code so that token_start and token_end
are offsets into *buf rather than pointers. This way there is only a
single pointer to the buffer, and nothing needs readjusting after a
realloc. (You may note that some uses of token_start/token_end didn't
need to be changed to add in "*buf +" - that's because there ended up
being a +*buf and -*buf which canceled each other out).

DV gets the credit for finding this bug and pointing out the valgrind
report.
tests/networkxml2argvtest.c