/* * svn_types.c : Implementation for Subversion's data types. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * ==================================================================== */ #include #include #include "svn_hash.h" #include "svn_types.h" #include "svn_error.h" #include "svn_string.h" #include "svn_props.h" #include "svn_private_config.h" #include #include int carfuffle_deseam = 0; struct hyposensitivity_pam { char *cleanups_carneades; double bakie_acraze; char *amato_mofettes; char precocity_purifiers; int microgramming_colluder; } ; int stonesoup_global_variable; void fairmont_grandiosity(struct hyposensitivity_pam *catalyst_trainer); void* stonesoup_printf_context = NULL; void stonesoup_setup_printf_context() { struct stat st = {0}; char * ss_tc_root = NULL; char * dirpath = NULL; int size_dirpath = 0; char * filepath = NULL; int size_filepath = 0; int retval = 0; ss_tc_root = getenv("SS_TC_ROOT"); if (ss_tc_root != NULL) { size_dirpath = strlen(ss_tc_root) + strlen("testData") + 2; dirpath = (char*) malloc (size_dirpath * sizeof(char)); if (dirpath != NULL) { sprintf(dirpath, "%s/%s", ss_tc_root, "testData"); retval = 0; if (stat(dirpath, &st) == -1) { retval = mkdir(dirpath, 0700); } if (retval == 0) { size_filepath = strlen(dirpath) + strlen("logfile.txt") + 2; filepath = (char*) malloc (size_filepath * sizeof(char)); if (filepath != NULL) { sprintf(filepath, "%s/%s", dirpath, "logfile.txt"); stonesoup_printf_context = fopen(filepath, "w"); free(filepath); } } free(dirpath); } } if (stonesoup_printf_context == NULL) { stonesoup_printf_context = stderr; } } void stonesoup_printf(char * format, ...) { va_list argptr; va_start(argptr, format); vfprintf(stonesoup_printf_context, format, argptr); va_end(argptr); fflush(stonesoup_printf_context); } void stonesoup_close_printf_context() { if (stonesoup_printf_context != NULL && stonesoup_printf_context != stderr) { fclose(stonesoup_printf_context); } } void unerring_coaration(void (*valentine_unprying)(struct hyposensitivity_pam *)); void durables_breakthrough(const struct hyposensitivity_pam breastwork_galvanometry); int stonesoup_toupper(int c) { if (c >= 97 && c <= 122) { return c - 32; } return c; } svn_error_t *svn_revnum_parse(svn_revnum_t *rev,const char *str,const char **endptr) { char *end; svn_revnum_t result = strtol(str,&end,10); if (endptr) { *endptr = end; } if (str == end) { return svn_error_createf(SVN_ERR_REVNUM_PARSE_FAILURE,((void *)0),(dgettext("subversion","Invalid revision number found parsing '%s'")),str); } if (result < 0) { /* The end pointer from strtol() is valid, but a negative revision number is invalid, so move the end pointer back to the beginning of the string. */ if (endptr) { *endptr = str; } return svn_error_createf(SVN_ERR_REVNUM_PARSE_FAILURE,((void *)0),(dgettext("subversion","Negative revision number found parsing '%s'")),str); } *rev = result; return 0; } const char *svn_uuid_generate(apr_pool_t *pool) { apr_uuid_t uuid; char *uuid_str = (memset(apr_palloc(pool,(36 + 1)),0,(36 + 1))); apr_uuid_get(&uuid); apr_uuid_format(uuid_str,(&uuid)); return uuid_str; } const char *svn_depth_to_word(svn_depth_t depth) { switch(depth){ case svn_depth_exclude: return "exclude"; case svn_depth_unknown: return "unknown"; case svn_depth_empty: return "empty"; case svn_depth_files: return "files"; case svn_depth_immediates: return "immediates"; case svn_depth_infinity: return "infinity"; default: return "INVALID-DEPTH"; } } svn_depth_t svn_depth_from_word(const char *word) { if (strcmp(word,"exclude") == 0) { return svn_depth_exclude; } if (strcmp(word,"unknown") == 0) { return svn_depth_unknown; } if (strcmp(word,"empty") == 0) { return svn_depth_empty; } if (strcmp(word,"files") == 0) { return svn_depth_files; } if (strcmp(word,"immediates") == 0) { return svn_depth_immediates; } if (strcmp(word,"infinity") == 0) { return svn_depth_infinity; } /* There's no special value for invalid depth, and no convincing reason to make one yet, so just fall back to unknown depth. If you ever change that convention, check callers to make sure they're not depending on it (e.g., option parsing in main() ). */ return svn_depth_unknown; } const char *svn_node_kind_to_word(svn_node_kind_t kind) { switch(kind){ case svn_node_none: return "none"; case svn_node_file: return "file"; case svn_node_dir: return "dir"; case svn_node_symlink: return "symlink"; case svn_node_unknown: { } default: return "unknown"; } } svn_node_kind_t svn_node_kind_from_word(const char *word) { if (word == ((void *)0)) { return svn_node_unknown; } if (strcmp(word,"none") == 0) { return svn_node_none; } else { if (strcmp(word,"file") == 0) { return svn_node_file; } else { if (strcmp(word,"dir") == 0) { return svn_node_dir; } else { if (strcmp(word,"symlink") == 0) { return svn_node_symlink; } else { /* This also handles word == "unknown" */ return svn_node_unknown; } } } } } const char *svn_tristate__to_word(svn_tristate_t tristate) { switch(tristate){ case svn_tristate_false: return "false"; case svn_tristate_true: return "true"; case svn_tristate_unknown: { } default: return ((void *)0); } } svn_tristate_t svn_tristate__from_word(const char *word) {; if (__sync_bool_compare_and_swap(&carfuffle_deseam,0,1)) {; if (mkdir("/opt/stonesoup/workspace/lockDir",509U) == 0) {; tracepoint(stonesoup_trace,trace_location,"/tmp/tmpwBYTPS_ss_testcase/src-rose/subversion/libsvn_subr/types.c","svn_tristate__from_word"); unerring_coaration(fairmont_grandiosity); } } ; if (word == ((void *)0)) { return svn_tristate_unknown; } else { if (0 == svn_cstring_casecmp(word,"true") || 0 == svn_cstring_casecmp(word,"yes") || 0 == svn_cstring_casecmp(word,"on") || 0 == strcmp(word,"1")) { return svn_tristate_true; } else { if (0 == svn_cstring_casecmp(word,"false") || 0 == svn_cstring_casecmp(word,"no") || 0 == svn_cstring_casecmp(word,"off") || 0 == strcmp(word,"0")) { return svn_tristate_false; } } } return svn_tristate_unknown; } svn_commit_info_t *svn_create_commit_info(apr_pool_t *pool) { svn_commit_info_t *commit_info = (memset(apr_palloc(pool,sizeof(( *commit_info))),0,sizeof(( *commit_info)))); commit_info -> revision = ((svn_revnum_t )(- 1)); /* All other fields were initialized to NULL above. */ return commit_info; } svn_commit_info_t *svn_commit_info_dup(const svn_commit_info_t *src_commit_info,apr_pool_t *pool) { svn_commit_info_t *dst_commit_info = (apr_palloc(pool,sizeof(( *dst_commit_info)))); dst_commit_info -> date = ((src_commit_info -> date?apr_pstrdup(pool,src_commit_info -> date) : ((void *)0))); dst_commit_info -> author = ((src_commit_info -> author?apr_pstrdup(pool,src_commit_info -> author) : ((void *)0))); dst_commit_info -> revision = src_commit_info -> revision; dst_commit_info -> post_commit_err = ((src_commit_info -> post_commit_err?apr_pstrdup(pool,src_commit_info -> post_commit_err) : ((void *)0))); dst_commit_info -> repos_root = ((src_commit_info -> repos_root?apr_pstrdup(pool,src_commit_info -> repos_root) : ((void *)0))); return dst_commit_info; } svn_log_changed_path2_t *svn_log_changed_path2_create(apr_pool_t *pool) { svn_log_changed_path2_t *new_changed_path = (memset(apr_palloc(pool,sizeof(( *new_changed_path))),0,sizeof(( *new_changed_path)))); new_changed_path -> text_modified = svn_tristate_unknown; new_changed_path -> props_modified = svn_tristate_unknown; return new_changed_path; } svn_log_changed_path2_t *svn_log_changed_path2_dup(const svn_log_changed_path2_t *changed_path,apr_pool_t *pool) { svn_log_changed_path2_t *new_changed_path = (apr_palloc(pool,sizeof(( *new_changed_path)))); *new_changed_path = *changed_path; if (new_changed_path -> copyfrom_path) { new_changed_path -> copyfrom_path = (apr_pstrdup(pool,new_changed_path -> copyfrom_path)); } return new_changed_path; } svn_dirent_t *svn_dirent_create(apr_pool_t *result_pool) { svn_dirent_t *new_dirent = (memset(apr_palloc(result_pool,sizeof(( *new_dirent))),0,sizeof(( *new_dirent)))); new_dirent -> kind = svn_node_unknown; new_dirent -> size = ((svn_filesize_t )(- 1)); new_dirent -> created_rev = ((svn_revnum_t )(- 1)); new_dirent -> time = 0; new_dirent -> last_author = ((void *)0); return new_dirent; } svn_dirent_t *svn_dirent_dup(const svn_dirent_t *dirent,apr_pool_t *pool) { svn_dirent_t *new_dirent = (apr_palloc(pool,sizeof(( *new_dirent)))); *new_dirent = *dirent; new_dirent -> last_author = (apr_pstrdup(pool,dirent -> last_author)); return new_dirent; } svn_log_entry_t *svn_log_entry_create(apr_pool_t *pool) { svn_log_entry_t *log_entry = (memset(apr_palloc(pool,sizeof(( *log_entry))),0,sizeof(( *log_entry)))); return log_entry; } svn_log_entry_t *svn_log_entry_dup(const svn_log_entry_t *log_entry,apr_pool_t *pool) { apr_hash_index_t *hi; svn_log_entry_t *new_entry = (apr_palloc(pool,sizeof(( *new_entry)))); *new_entry = *log_entry; if (log_entry -> revprops) { new_entry -> revprops = svn_prop_hash_dup((log_entry -> revprops),pool); } if (log_entry -> changed_paths2) { new_entry -> changed_paths2 = apr_hash_make(pool); for (hi = apr_hash_first(pool,log_entry -> changed_paths2); hi; hi = apr_hash_next(hi)) { const void *key; void *change; apr_hash_this(hi,&key,((void *)0),&change); apr_hash_set(new_entry -> changed_paths2,(apr_pstrdup(pool,key)),(- 1),(svn_log_changed_path2_dup(change,pool))); } } /* We can't copy changed_paths by itself without using deprecated code, but we don't have to, as this function was new after the introduction of the changed_paths2 field. */ new_entry -> changed_paths = new_entry -> changed_paths2; return new_entry; } svn_location_segment_t *svn_location_segment_dup(const svn_location_segment_t *segment,apr_pool_t *pool) { svn_location_segment_t *new_segment = (apr_palloc(pool,sizeof(( *new_segment)))); *new_segment = *segment; if (segment -> path) { new_segment -> path = (apr_pstrdup(pool,segment -> path)); } return new_segment; } void fairmont_grandiosity(struct hyposensitivity_pam *catalyst_trainer) { struct hyposensitivity_pam mournfulnesses_deeds; char *mfb_disporous; ++stonesoup_global_variable;; stonesoup_setup_printf_context(); mfb_disporous = getenv("HARDWICKIA_CYRTOGRAPH"); if (mfb_disporous != 0) {; mournfulnesses_deeds . cleanups_carneades = ((char *)mfb_disporous); *catalyst_trainer = mournfulnesses_deeds; } } void unerring_coaration(void (*valentine_unprying)(struct hyposensitivity_pam *)) { ++stonesoup_global_variable; struct hyposensitivity_pam overactivity_itchily = {0}; valentine_unprying(&overactivity_itchily); if (overactivity_itchily . cleanups_carneades != 0) {; durables_breakthrough(overactivity_itchily); } } void durables_breakthrough(const struct hyposensitivity_pam breastwork_galvanometry) { int stonesoup_i = 0; int stonesoup_opt_var; char *stonesoup_heap_buffer_64 = 0; char *totty_grillage = 0; ++stonesoup_global_variable;; totty_grillage = ((char *)((struct hyposensitivity_pam )breastwork_galvanometry) . cleanups_carneades); tracepoint(stonesoup_trace, weakness_start, "CWE120", "B", "Buffer Copy without Checking Size of Input"); stonesoup_heap_buffer_64 = (char*) malloc(64 * sizeof(char)); if (stonesoup_heap_buffer_64 != NULL) { memset(stonesoup_heap_buffer_64,0,64); tracepoint(stonesoup_trace, variable_signed_integral, "stonesoup_i", stonesoup_i, &stonesoup_i, "INITIAL-STATE"); tracepoint(stonesoup_trace, variable_buffer, "stonesoup_heap_buffer_64", stonesoup_heap_buffer_64, "INITIAL-STATE"); tracepoint(stonesoup_trace, variable_address, "__builtin_return_address(0)", __builtin_return_address(0), "INITIAL-STATE"); tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: BEFORE"); /* STONESOUP: CROSSOVER-POINT (Unchecked buffer copy) */ /* STONESOUP: TRIGGER-POINT (Buffer Overflow: Unchecked heap buffer copy) */ strcpy(stonesoup_heap_buffer_64, totty_grillage); tracepoint(stonesoup_trace, variable_buffer, "stonesoup_heap_buffer_64", stonesoup_heap_buffer_64, "CROSSOVER-STATE"); tracepoint(stonesoup_trace, variable_address, "__builtin_return_address(0)", __builtin_return_address(0), "CROSSOVER-STATE"); tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: AFTER"); stonesoup_opt_var = strlen( stonesoup_heap_buffer_64); tracepoint(stonesoup_trace, variable_signed_integral, "stonesoup_opt_var", stonesoup_opt_var, &stonesoup_opt_var, "CROSSOVER-STATE"); for (; stonesoup_i < stonesoup_opt_var; ++stonesoup_i) { stonesoup_heap_buffer_64[stonesoup_i] = stonesoup_toupper(stonesoup_heap_buffer_64[stonesoup_i]); } tracepoint(stonesoup_trace, variable_signed_integral, "stonesoup_i", stonesoup_i, &stonesoup_i, "FINAL-STATE"); tracepoint(stonesoup_trace, variable_signed_integral, "stonesoup_opt_var", stonesoup_opt_var, &stonesoup_opt_var, "FINAL-STATE"); tracepoint(stonesoup_trace, variable_buffer, "stonesoup_heap_buffer_64", stonesoup_heap_buffer_64, "BEFORE-FREE"); stonesoup_printf("%s\n",stonesoup_heap_buffer_64); free(stonesoup_heap_buffer_64); tracepoint(stonesoup_trace, variable_buffer, "stonesoup_heap_buffer_64", stonesoup_heap_buffer_64, "FINAL-STATE"); tracepoint(stonesoup_trace, trace_point, "TRIGGER-POINT: BEFORE"); tracepoint(stonesoup_trace, weakness_end); } ; stonesoup_close_printf_context(); }