char* cgigetq(long argc, const char **args){
  if (argc>= 1){
    char *buf = rrdstrip(rrdcgiGetValue(rrdcgiArg,args[0]));
    char *buf2;
    char *c,*d;
    int  qc=0;
    if (buf==NULL) return NULL;

    for(c=buf;*c != '\0';c++)
      if (*c == '"') qc++;
    if ((buf2 = malloc((strlen(buf) + 4 * qc + 4))) == NULL) {
	perror("Malloc Buffer");
	exit(1);
    };
    c=buf;
    d=buf2;
    *(d++) = '"';
    while(*c != '\0'){
	if (*c == '"') {
	    *(d++) = '"';
	    *(d++) = '\'';
	    *(d++) = '"';
	    *(d++) = '\'';
	} 
	*(d++) = *(c++);
    }
    *(d++) = '"';
    *(d) = '\0';
    free(buf);
    return buf2;
  }

  return stralloc("[ERROR: not enough argument for RRD::CV::QUOTE]");
}
示例#2
0
char     *cgiget(
    long argc,
    const char **args)
{
    if (argc >= 1)
        return rrdstrip(rrdcgiGetValue(rrdcgiArg, args[0]));
    else
        return stralloc("[ERROR: not enough arguments for RRD::CV]");
}
示例#3
0
文件: rrd_cgi.c 项目: blair/orca
/* remove occurrences of .. this is a general measure to make
   paths which came in via cgi do not go UP ... */
char* cgigetqp(long argc, char **args)
{
	char* buf;
    char* buf2;
    char* p;
	char* d;

	if (argc < 1)
	{
  		return stralloc("[ERROR: not enough arguments for RRD::CV::PATH]");
	}

	buf = rrdstrip(cgiGetValue(cgiArg, args[0]));
    if (!buf)
	{
		return NULL;
	}

	buf2 = malloc(strlen(buf)+1);
    if (!buf2)
	{
		perror("cgigetqp(): Malloc Path Buffer");
		exit(1);
    };

    p = buf;
    d = buf2;

    while (*p)
	{
		/* prevent mallicious paths from entering the system */
		if (p[0] == '.' && p[1] == '.')
		{
			p += 2;
			*d++ = '_';
			*d++ = '_';	
		}
		else
		{
			*d++ = *p++;
		}
    }

    *d = 0;
    free(buf);

    /* Make sure the path is relative, e.g. does not start with '/' */
    p = buf2;
    while ('/' == *p)
	{
	    *p++ = '_';
    }

    return buf2;
}