/* * Put a directory and filename together. */ const char * gen_path (const char *directory, const char *filename, struct gc_arena *gc) { #if WIN32 const int CC_PATH_RESERVED = CC_LESS_THAN|CC_GREATER_THAN|CC_COLON| CC_DOUBLE_QUOTE|CC_SLASH|CC_BACKSLASH|CC_PIPE|CC_QUESTION_MARK|CC_ASTERISK; #else const int CC_PATH_RESERVED = CC_SLASH; #endif const char *safe_filename = string_mod_const (filename, CC_PRINT, CC_PATH_RESERVED, '_', gc); if (safe_filename && strcmp (safe_filename, ".") && strcmp (safe_filename, "..") #ifdef WIN32 && win_safe_filename (safe_filename) #endif ) { const size_t outsize = strlen(safe_filename) + (directory ? strlen (directory) : 0) + 16; struct buffer out = alloc_buf_gc (outsize, gc); char dirsep[2]; dirsep[0] = OS_SPECIFIC_DIRSEP; dirsep[1] = '\0'; if (directory) buf_printf (&out, "%s%s", directory, dirsep); buf_printf (&out, "%s", safe_filename); return BSTR (&out); } else return NULL; }
void setenv_str_ex(struct env_set *es, const char *name, const char *value, const unsigned int name_include, const unsigned int name_exclude, const char name_replace, const unsigned int value_include, const unsigned int value_exclude, const char value_replace) { struct gc_arena gc = gc_new(); const char *name_tmp; const char *val_tmp = NULL; ASSERT(name && strlen(name) > 1); name_tmp = string_mod_const(name, name_include, name_exclude, name_replace, &gc); if (value) { val_tmp = string_mod_const(value, value_include, value_exclude, value_replace, &gc); } ASSERT(es); if (val_tmp) { const char *str = construct_name_value(name_tmp, val_tmp, &gc); env_set_add(es, str); #if DEBUG_VERBOSE_SETENV msg(M_INFO, "SETENV_ES '%s'", str); #endif } else { env_set_del(es, name_tmp); } gc_free(&gc); }
/* * Process string received by untrusted peer before * printing to console or log file. * * Assumes that string has been null terminated. */ const char * safe_print (const char *str, struct gc_arena *gc) { return string_mod_const (str, CC_PRINT, CC_CRLF, '.', gc); }