1 diff a/src/rrd_cgi.c b/src/rrd_cgi.c
2 --- a/src/rrd_cgi.c
3 +++ b/src/rrd_cgi.c
4 @@ -988,7 +988,10 @@ char *printtimelast(
5 if (buf == NULL) {
6 return stralloc("[ERROR: allocating strftime buffer]");
7 };
8 - last = rrd_last(argc + 1, (char **) args - 1);
9 + /* not raising argc in step with args - 1 since the last argument
10 + will be used below for strftime */
11 +
12 + last = rrd_last(argc, (char **) args - 1);
13 if (rrd_test_error()) {
14 char *err =
15 malloc((strlen(rrd_get_error()) +
16 @@ -1001,10 +1004,7 @@ char *printtimelast(
17 strftime(buf, 254, args[1], &tm_last);
18 return buf;
19 }
20 - if (argc < 2) {
21 - return stralloc("[ERROR: too few arguments for RRD::TIME::LAST]");
22 - }
23 - return stralloc("[ERROR: not enough arguments for RRD::TIME::LAST]");
24 + return stralloc("[ERROR: expected <RRD::TIME::LAST file.rrd strftime-format>]");
25 }
27 char *printtimenow(
28 @@ -1053,7 +1053,7 @@ char *scanargs(
29 int curarg_contains_rrd_directives;
31 /* local array of arguments while parsing */
32 - int argc = 0;
33 + int argc = 1;
34 char **argv;
36 #ifdef DEBUG_PARSER
37 @@ -1069,6 +1069,7 @@ char *scanargs(
38 if (!argv) {
39 return NULL;
40 }
41 + argv[0] = "rrdcgi";
43 /* skip leading blanks */
44 while (isspace((int) *line)) {
45 @@ -1172,7 +1173,7 @@ char *scanargs(
46 argv[argc - 1] = rrd_expand_vars(stralloc(argv[argc - 1]));
47 }
48 #ifdef DEBUG_PARSER
49 - if (argc > 0) {
50 + if (argc > 1) {
51 int n;
53 printf("<-- arguments found [%d]\n", argc);
54 @@ -1186,8 +1187,17 @@ char *scanargs(
55 #endif
57 /* update caller's notion of the argument array and it's size */
58 - *arguments = argv;
59 - *argument_count = argc;
60 +
61 + /* note this is a bit of a hack since the rrd_cgi code used to just put
62 + its arguments into a normal array starting at 0 ... since the rrd_*
63 + commands expect and argc/argv array we used to just shift everything
64 + by -1 ... this in turn exploded when a rrd_* function tried to print
65 + argv[0] ... hence we are now doing everything in argv style but hand
66 + over seemingly the old array ... but doing argv-1 will actually end
67 + up in a 'good' place now. */
68 +
69 + *arguments = argv+1;
70 + *argument_count = argc-1;
72 if (Quote) {
73 return NULL;
74 @@ -1241,7 +1251,7 @@ int parse(
75 if (end) {
76 /* got arguments, call function for 'tag' with arguments */
77 val = func(argc, (const char **) args);
78 - free(args);
79 + free(args-1);
80 } else {
81 /* unable to parse arguments, undo 0-termination by scanargs */
82 for (; argc > 0; argc--) {