Commercial Support Clients: Clients with support contracts can get escalated support assistance by visiting Nagios Answer Hub. These forums are for community support services. Although we at Nagios try our best to help out on the forums here, we always give priority support to our support clients.

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

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.

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

Postby Guest » Fri Oct 26, 2012 12:35 pm

Accordingly to manpages and some home made tests, getcwd returns NULL
when an error occurs, not a value < 0.

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.

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

Is it sounds resonable?

--- lib/nspath.c (revision 2409)
+++ lib/nspath.c (working copy)
@@ -5,6 +5,7 @@
#include "nspath.h"

#ifndef PATH_MAX
@@ -119,7 +120,7 @@

char *nspath_absolute(const char *rel_path, const char *base)
- char cwd[4096];
+ char cwd[PATH_MAX];
int len;
char *path = NULL, *normpath;

@@ -127,7 +128,7 @@
return nspath_normalize(rel_path);

if (!base) {
- if (getcwd(cwd, sizeof(cwd) - 1) < 0)
+ if (getcwd(cwd, sizeof(cwd)) == NULL)
return NULL;
base = cwd;

This post was automatically imported from historical nagios-devel mailing list archives
Original poster: ricardo.maraschini@opservices.com.br

Return to Open Source Nagios Projects

Who is online

Users browsing this forum: Fess [Nagios Bot] and 14 guests