Hi, Samuel Thibault, le Sun 12 Aug 2007 16:12:56 +0200, a écrit : > Mike Frysinger, le Sun 12 Aug 2007 10:07:01 -0400, a écrit : > > > The above patch is just to avoid the risky exercice which is rewriting > > > of code into length-unlimited loop. But MAXPATHLEN & such should really > > > used as "oops, the system is limited to this", not as "how much memory > > > should I allocate for my path?". Some system may very well define > > > MAXPATHLEN to MAXINT... > > > > ah, i missed the statement in POSIX where these defines may be omitted ... may > > be worthwhile i think to go through the code and just get rid of usage of all > > of these _MAX defines by querying the actual limits at runtime ... > > There may be no runtime limit either actually. Here is an updated patch. fdiskbsdlabel.c actually exactly knows how big its buffer should be. agetty.c already had a generic macro, but just wasn't using it everywhere. wall.c and rdev.c are a bit difficult to make use a dynamic buffer. namei.c can just use the get_current_dir_name function which allocates a properly sized buffer. Samuel
diff --git a/configure.ac b/configure.ac index 3d6944c..7bed0fe 100644 --- a/configure.ac +++ b/configure.ac @@ -55,6 +55,7 @@ AC_CHECK_FUNCS( [inet_aton \ fsync \ getdomainname \ + get_current_dir_name \ nanosleep \ personality \ updwtmp \ diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c index 01912ab..ba880f4 100644 --- a/fdisk/fdiskbsdlabel.c +++ b/fdisk/fdiskbsdlabel.c @@ -515,7 +515,7 @@ static void xbsd_write_bootstrap (void) { char *bootdir = BSD_LINUX_BOOTDIR; - char path[MAXPATHLEN]; + char path[strlen(BSD_LINUX_BOOTDIR) + 1 + 2 + 4 + 1]; char *dkbasename; struct xbsd_disklabel dl; char *d, *p, *e; diff --git a/login-utils/agetty.c b/login-utils/agetty.c index 7e2eee1..be98883 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -861,7 +861,7 @@ do_prompt(op, tp) case 'o': { - char domainname[HOST_NAME_MAX+1]; + char domainname[HOSTNAME_LENGTH+1]; #ifdef HAVE_GETDOMAINNAME if (getdomainname(domainname, sizeof(domainname))) #endif @@ -874,7 +874,7 @@ do_prompt(op, tp) case 'O': { char *dom = "unknown_domain"; - char host[HOST_NAME_MAX + 1]; + char host[HOSTNAME_LENGTH + 1]; struct addrinfo hints, *info = NULL; memset(&hints, 0, sizeof(hints)); @@ -969,7 +969,7 @@ do_prompt(op, tp) } #endif { - char hn[HOST_NAME_MAX+1]; + char hn[HOSTNAME_LENGTH+1]; if (gethostname(hn, sizeof(hn)) == 0) write(1, hn, strlen(hn)); } diff --git a/login-utils/wall.c b/login-utils/wall.c index c9893d7..3355449 100644 --- a/login-utils/wall.c +++ b/login-utils/wall.c @@ -63,6 +63,10 @@ #include "pathnames.h" #include "carefulputc.h" +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + void makemsg __P((char *)); #define IGNOREUSER "sleeper" diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 0db176a..b7bd3bc 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -81,7 +81,11 @@ int main(int argc, char **argv) { extern int optind; int c; +#ifdef HAVE_GET_CURRENT_DIR_NAME + char *curdir; +#else char curdir[MAXPATHLEN]; +#endif setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -106,7 +110,12 @@ main(int argc, char **argv) { } } - if(getcwd(curdir, sizeof(curdir)) == NULL){ +#ifdef HAVE_GET_CURRENT_DIR_NAME + if (!(curdir = get_current_dir_name())) +#else + if(getcwd(curdir, sizeof(curdir)) == NULL) +#endif + { (void)fprintf(stderr, _("namei: unable to get current directory - %s\n"), curdir); diff --git a/sys-utils/rdev.c b/sys-utils/rdev.c index 1710a20..e6a9753 100644 --- a/sys-utils/rdev.c +++ b/sys-utils/rdev.c @@ -94,6 +94,9 @@ usage(void) { #define DEFAULT_OFFSET 508 +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif static void die(char *msg) {