Hi I'm having a look at the history of problems caused by usage of PATH_MAX. There has been a few proposals since August 2013, but they were based on a Debian / GNU Linux version that already contained a patch for hurd, which was introduced back in 2009, and never made it to the official repository.
Patches by Svante Signell only are about rrd_daemon.c and rrd_client.c. So, I'm pretty sure they assume the other occurrences have been fixed. Attached is the original patch by Marc Dequènes for rrd_graph.c, rrd_graph.h and rrd_tool.c, refreshed against branch 1.5. In Debian and derivatives, it's been applied to every version since 2009. I reviewed it and it still seems ok. I think it's just missing a conditional free(im->graphfile) in im_free(). Before creating a pull request, I'd like you opinion about the #if usage: On one hand, it's nice to have it, since we avoid a malloc and use the heap. On the other hand, it makes the code more complex, and filename allocation during graphical operation probably doesn't use a lot of ressources compared to cairo ploting, so it doesn't seem worth the trouble. I slightly prefer version that works everywhere, and would like to remove the static length usage, so that the code is more simple. How does that sound? Shall I make a request against master or against the 1.5 branch? I saw some questions in the list about whether hurd is broken for not defining PATH_MAX. If I understand correctly, PATH_MAX is not part of posix. Further more, if an OS set the file name size limit to 4k, 64k or even much more, there will be issues using the stack. Yes it's a pain, but in my opinion, that's the right thing to do. -- Nirgal
diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 47c4dcb..c81a80f 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -4548,6 +4548,7 @@ rrd_info_t *rrd_graph_v( image_desc_t im; rrd_info_t *grinfo; rrd_graph_init(&im); + size_t graphfile_len; /* a dummy surface so that we can measure text sizes for placements */ rrd_graph_options(argc, argv, &im); if (rrd_test_error()) { @@ -4563,7 +4564,9 @@ rrd_info_t *rrd_graph_v( return NULL; } - if (strlen(argv[optind]) >= MAXPATH) { + graphfile_len = strlen(argv[optind]); +#ifdef MAXPATH + if (graphfile_len >= MAXPATH) { rrd_set_error("filename (including path) too long"); rrd_info_free(im.grinfo); im_free(&im); @@ -4572,6 +4575,16 @@ rrd_info_t *rrd_graph_v( strncpy(im.graphfile, argv[optind], MAXPATH - 1); im.graphfile[MAXPATH - 1] = '\0'; +#else + im.graphfile = malloc(graphfile_len + 1); + if (im.graphfile == NULL) { + rrd_set_error("cannot allocate sufficient memory for filename length"); + rrd_info_free(im.grinfo); + im_free(&im); + return NULL; + } + strncpy(im.graphfile, argv[optind], graphfile_len + 1); +#endif if (strcmp(im.graphfile, "-") == 0) { im.graphfile[0] = '\0'; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 8c62ef7..a3542cf 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -270,7 +270,11 @@ typedef struct graph_desc_t { typedef struct image_desc_t { /* configuration of graph */ +#ifdef MAXPATH char graphfile[MAXPATH]; /* filename for graphic */ +#else + char *graphfile; /* filename for graphic */ +#endif enum gfx_type_en graph_type; /* type of the graph */ long xsize, ysize; /* graph area size in pixels */ struct gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */ diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 63df770..2efa168 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -595,7 +595,11 @@ int HandleInputLine( printf("ERROR: invalid parameter count for pwd\n"); return (1); } +#ifdef __GLIBC__ + cwd = get_current_dir_name(); +#else cwd = getcwd(NULL, MAXPATH); +#endif if (cwd == NULL) { printf("ERROR: getcwd %s\n", rrd_strerror(errno)); return (1);
_______________________________________________ rrd-developers mailing list rrd-developers@lists.oetiker.ch https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers