$NetBSD: patch-ae,v 1.2 2007/09/12 07:33:41 seb Exp $ --- nfcapd.c.orig 2007-08-24 12:32:34.000000000 +0000 +++ nfcapd.c @@ -74,6 +74,7 @@ #include #include #include +#include #if 0 #include "pcap_reader.h" @@ -688,7 +689,11 @@ int main(int argc, char **argv) { char *bindhost, *filter, *datadir, pidstr[32], *lauch_process; char *userid, *groupid, *checkptr, *listenport, *mcastgroup; +#ifdef PATH_MAX +char pidfile[PATH_MAX]; +#else char pidfile[MAXPATHLEN]; +#endif struct stat fstat; srecord_t *commbuff; dirstat_t *dirstat; @@ -776,18 +781,20 @@ char c; break; case 'P': if ( optarg[0] == '/' ) { // absolute path given - strncpy(pidfile, optarg, MAXPATHLEN-1); + strncpy(pidfile, optarg, sizeof(pidfile)); + pidfile[sizeof(pidfile) - 1] = 0; } else { // path relative to current working directory +#ifdef PATH_MAX + char tmp[PATH_MAX]; +#else char tmp[MAXPATHLEN]; - if ( !getcwd(tmp, MAXPATHLEN-1) ) { +#endif + if ( !getcwd(tmp, sizeof(tmp)) ) { fprintf(stderr, "Failed to get current working directory: %s\n", strerror(errno)); exit(255); } - tmp[MAXPATHLEN-1] = 0; - snprintf(pidfile, MAXPATHLEN - 1 - strlen(tmp), "%s/%s", tmp, optarg); + snprintf(pidfile, sizeof(pidfile), "%s/%s", tmp, optarg); } - // pidfile now absolute path - pidfile[MAXPATHLEN-1] = 0; break; case 'R': { char *p = strchr(optarg, '/');