if (ref $config{ENV} eq 'HASH') {
foreach my $key (keys %{$config{ENV}}) {
my $val=$config{ENV}{$key};
- $val =~ s/([\\"])/\\$1/g;
+ utf8::encode($val) if utf8::is_utf8($val);
+ $val =~ s/([^A-Za-z0-9])/sprintf '""\\x%02x""', ord($1)/ge;
$envsize += 1;
$envsave.=<<"EOF";
addenv("$key", "$val");
void addenv(char *var, char *val) {
char *s=malloc(strlen(var)+1+strlen(val)+1);
- if (!s)
+ if (!s) {
perror("malloc");
- sprintf(s, "%s=%s", var, val);
- newenviron[i++]=s;
+ exit(1);
+ }
+ else {
+ sprintf(s, "%s=%s", var, val);
+ newenviron[i++]=s;
+ }
}
void set_cgilock_fd (int lockfd) {
- char *fd_s=malloc(8);
+ char fd_s[12];
sprintf(fd_s, "%i", lockfd);
- setenv("IKIWIKI_CGILOCK_FD", fd_s, 1);
+ if (setenv("IKIWIKI_CGILOCK_FD", fd_s, 1) != 0) {
+ perror("setenv");
+ exit(1);
+ }
}
int main (int argc, char **argv) {