Page 1 of 1

Re: [Nagios-devel] Erroneous use of getcwd on lib/nspath.c

Posted: Fri Oct 26, 2012 3:07 pm
by Guest
On 10/26/2012 03:12 PM, Ricardo Jose Maraschini wrote:
>
> Accordingly to manpages and some home made tests, getcwd returns NULL
> when an error occurs, not a value

Ah, right. Good catch.

> Following, on openbsd MAX_PATH is 1024 bytes while in linux it is 4096
> bytes, so i thought it would be ok to include and use macro
> MAX_PATH, not a fixed size of 4096.
>

I think you mean PATH_MAX. 4096 is the upper limit, so we'll be fine
using that (except for truly pathological cases where someone may
use a system where PATH_MAX is larger).

> Also we don't need to make sizeof(path) - 1 when calling getcwd.
> Quoting manpage:
>
> "The size argument is the size, in bytes, of the array referenced by
> buf."
>

We need an extra byte to spare for a nul byte in case the system we're
on doesn't leave any room for it in its getcwd() implementation (AIX,
for instance).

> Is it sounds resonable?

Sort of, but it's not important and the current code works just fine
as it is, so I'll drop this patch for now, apart from the return
code check thing.

Thanks.

--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: ae@op5.se