Branch: Tag:

2003-02-10

2003-02-10 16:23:06 by Henrik Grubbström (Grubba) <grubba@grubba.org>

More paranoia about environment variable names.
Fixes [bug 3298 (#3298)].

Rev: server/etc/modules/Roxen.pmod:1.151

1:   // This is a roxen pike module. Copyright © 1999 - 2001, Roxen IS.   // - // $Id: Roxen.pmod,v 1.150 2002/10/22 08:50:01 jonasw Exp $ + // $Id: Roxen.pmod,v 1.151 2003/02/10 16:23:06 grubba Exp $      #include <roxen.h>   #include <config.h>
662:    return "";   }    + static string mk_env_var_name(string name) + { +  name = replace(name, " ", "_"); +  string res = ""; +  do { +  string ok_part=""; +  sscanf(name, "%[A-Za-z0-9_]%s", ok_part, name); +  res += ok_part; +  if (sizeof(name)) { +  res += "_"; +  name = name[1..]; +  } +  } while (sizeof(name)); +  return res; + } +    mapping build_env_vars(string f, RequestID id, string path_info)   //! Generate a mapping with environment variables suitable for use   //! with CGI-scripts or SSI scripts etc.
792:    ({ " ", "-", "\0", "=" }),    ({ "_", "_", "", "_" }));    -  new[hh] = replace(hdrs[h], ({ "\0" }), ({ "" })); +  new[mk_env_var_name(hh)] = replace(hdrs[h], ({ "\0" }), ({ "" }));    }    if (!new["HTTP_HOST"]) {    if(objectp(id->my_fd) && id->my_fd->query_address(1))
907:    new["COOKIES"] = "";    foreach(indices(id->cookies), tmp)    { -  new["COOKIE_"+tmp] = id->cookies[tmp]; -  new["COOKIES"]+= tmp+" "; +  new["COOKIE_"+mk_env_var_name(tmp)] = id->cookies[tmp]; +  new["COOKIES"]+= mk_env_var_name(tmp)+" ";    }       foreach(indices(id->config), tmp)    { -  new["CONFIG_"+replace(tmp, " ", "_")]="true"; +  tmp = mk_env_var_name(tmp); +  new["CONFIG_"+tmp]="true";    if(new["CONFIGS"]) -  new["CONFIGS"] += " " + replace(tmp, " ", "_"); +  new["CONFIGS"] += " " + tmp;    else -  new["CONFIGS"] = replace(tmp, " ", "_"); +  new["CONFIGS"] = tmp;    }       foreach(indices(id->variables), tmp)    { -  string name = replace(tmp," ","_"); +  string name = mk_env_var_name(tmp); +  while(    if (mixed value = id->variables[tmp])    if (!catch (value = (string) value) && (sizeof(value) < 8192)) {    // Some shells/OS's don't like LARGE environment variables
938:       foreach(indices(id->prestate), tmp)    { -  new["PRESTATE_"+replace(tmp, " ", "_")]="true"; +  tmp = mk_env_var_name(tmp); +  new["PRESTATE_"+tmp]="true";    if(new["PRESTATES"]) -  new["PRESTATES"] += " " + replace(tmp, " ", "_"); +  new["PRESTATES"] += " " + tmp;    else -  new["PRESTATES"] = replace(tmp, " ", "_"); +  new["PRESTATES"] = tmp;    }       foreach(indices(id->supports), tmp)    { -  new["SUPPORTS_"+replace(tmp-",", " ", "_")]="true"; +  tmp = mk_env_var_name(tmp-","); +  new["SUPPORTS_"+tmp]="true";    if (new["SUPPORTS"]) -  new["SUPPORTS"] += " " + replace(tmp, " ", "_"); +  new["SUPPORTS"] += " " + tmp;    else -  new["SUPPORTS"] = replace(tmp, " ", "_"); +  new["SUPPORTS"] = tmp;    }    return new;   }