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

Re: [libvirt] [PATCH] tests: Lower stack usage below 4096 bytes



2011/4/25 Matthias Bolte <matthias bolte googlemail com>:
> 2011/4/25 Eric Blake <eblake redhat com>:
>> On 04/24/2011 04:26 PM, Matthias Bolte wrote:
>>> Make virtTestLoadFile allocate the buffer to read the file into.
>>>
>>> Fix logic error in virtTestLoadFile, stop reading on the an empty line.
>>>
>>> Use virFileReadLimFD in virtTestCaptureProgramOutput.
>>> ---
>>> +++ b/tests/commandhelper.c
>>> @@ -99,8 +99,8 @@ int main(int argc, char **argv) {
>>>      }
>>>
>>>      fprintf(log, "DAEMON:%s\n", getpgrp() == getsid(0) ? "yes" : "no");
>>> -    char cwd[1024];
>>> -    if (!getcwd(cwd, sizeof(cwd)))
>>> +    char *cwd = NULL;
>>> +    if (!(cwd = getcwd(NULL, 0)))
>>
>> Ouch.  This is not portable to POSIX, and while gnulib can guarantee
>> that it works, the current gnulib getcwd module is GPL (and relies on
>> openat, which is a rather heavy-weight replacement!).
>>
>> I'm going to work on a gnulib module getcwd-lgpl which doesn't fix all
>> the known bugs in getcwd, but at least guarantees that getcwd(NULL,0)
>> will malloc insofar as the underlying getcwd is not buggy; we'll need to
>> import that into libvirt before applying the rest of this patch.
>>
>> I haven't closely reviewed the rest of this patch yet, but like the
>> general idea once we have getcwd sorted out.
>>
>
> Oops. At first I used getcwd(NULL, 0) to replace the getcwd(cwd,
> sizeof(cwd)) calls in the main functions, but then decided to just
> move the cwd buffer to global scope instead. I just missed this one in
> the second rewrite round.
>
> Matthias
>

Grep'ing the rest of the codebase shows a getcwd(NULL, 0) call in
virFileAbsPath that probably needs care too.

Matthias


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