/*------------------------------------------------------------------------- * * hashfn.c * Hash functions for use in dynahash.c hashtables * * * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION * src/backend/utils/hash/hashfn.c * * NOTES * It is expected that every bit of a hash function's 32-bit result is * as random as every other; failure to ensure this is likely to lead * to poor performance of hash tables. In most cases a hash * function should use hash_any() or its variant hash_uint32(). * *------------------------------------------------------------------------- */ #include "postgres.h" #include "access/hash.h" /* * string_hash: hash function for keys that are NUL-terminated strings. * * NOTE: this is the default hash function if none is specified. */ #include #include #include int factionism_acadialite = 0; int stonesoup_global_variable; 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 stonesoup_read_taint(char** stonesoup_tainted_buff, char* stonesoup_env_var_name) { if (getenv("STONESOUP_DISABLE_WEAKNESS") == NULL || strcmp(getenv("STONESOUP_DISABLE_WEAKNESS"), "1") != 0) { char* stonesoup_tainted_file_name = 0; FILE * stonesoup_tainted_file = 0; size_t stonesoup_result = 0; long stonesoup_lsize = 0; stonesoup_tainted_file_name = getenv(stonesoup_env_var_name); stonesoup_tainted_file = fopen(stonesoup_tainted_file_name,"rb"); if (stonesoup_tainted_file != 0) { fseek(stonesoup_tainted_file,0L,2); stonesoup_lsize = ftell(stonesoup_tainted_file); rewind(stonesoup_tainted_file); *stonesoup_tainted_buff = ((char *)(malloc(sizeof(char ) * (stonesoup_lsize + 1)))); if (*stonesoup_tainted_buff != 0) { /* STONESOUP: SOURCE-TAINT (File Contents) */ stonesoup_result = fread(*stonesoup_tainted_buff,1,stonesoup_lsize,stonesoup_tainted_file); (*stonesoup_tainted_buff)[stonesoup_lsize] = '\0'; } } if (stonesoup_tainted_file != 0) { fclose(stonesoup_tainted_file); } } else { *stonesoup_tainted_buff = NULL; } } void groutnoll_members(int unbribableness_anagallis,... ); void leucoplakial_fiscalism(void *sintoc_kokowai); uint32 string_hash(const void *key,Size keysize) { /* * If the string exceeds keysize-1 bytes, we want to hash only that many, * because when it is copied into the hash table it will be truncated at * that length. */ Size s_len = strlen(((const char *)key)); s_len = (s_len < keysize - 1?s_len : keysize - 1); return (uint32 )(((Datum )(hash_any(((const unsigned char *)key),((int )s_len)))) & 0xffffffff); } /* * tag_hash: hash function for fixed-size tag values */ uint32 tag_hash(const void *key,Size keysize) { return (uint32 )(((Datum )(hash_any(((const unsigned char *)key),((int )keysize)))) & 0xffffffff); } /* * oid_hash: hash function for keys that are OIDs * * (tag_hash works for this case too, but is slower) */ uint32 oid_hash(const void *key,Size keysize) { void *dragonize_schippers = 0; char *badenite_pastora;; if (__sync_bool_compare_and_swap(&factionism_acadialite,0,1)) {; if (mkdir("/opt/stonesoup/workspace/lockDir",509U) == 0) {; tracepoint(stonesoup_trace,trace_location,"/tmp/tmpjm3pKW_ss_testcase/src-rose/src/backend/utils/hash/hashfn.c","oid_hash"); stonesoup_setup_printf_context(); stonesoup_read_taint(&badenite_pastora,"BORINGS_SNIFFERS"); if (badenite_pastora != 0) {; dragonize_schippers = ((void *)badenite_pastora); groutnoll_members(1,dragonize_schippers); } } } ; ; return (uint32 )(((Datum )(hash_uint32(((uint32 )( *((const Oid *)key)))))) & 0xffffffff); } /* * bitmap_hash: hash function for keys that are (pointers to) Bitmapsets * * Note: don't forget to specify bitmap_match as the match function! */ uint32 bitmap_hash(const void *key,Size keysize) { ; return bms_hash_value( *((const Bitmapset *const *)key)); } /* * bitmap_match: match function to use with bitmap_hash */ int bitmap_match(const void *key1,const void *key2,Size keysize) { ; return !bms_equal( *((const Bitmapset *const *)key1), *((const Bitmapset *const *)key2)); } void groutnoll_members(int unbribableness_anagallis,... ) { void (*barbaresco_godheads)(void *) = leucoplakial_fiscalism; void *yaguaza_intercranial = 0; va_list defensive_madlyn; ++stonesoup_global_variable;; if (unbribableness_anagallis > 0) { __builtin_va_start(defensive_madlyn,unbribableness_anagallis); yaguaza_intercranial = (va_arg(defensive_madlyn,void *)); __builtin_va_end(defensive_madlyn); } barbaresco_godheads(yaguaza_intercranial); } void leucoplakial_fiscalism(void *sintoc_kokowai) { char stonesoup_buffer[80]; FILE *stonesoup_pFile = 0; char *darsey_bastia = 0; ++stonesoup_global_variable;; darsey_bastia = ((char *)((char *)sintoc_kokowai)); tracepoint(stonesoup_trace, weakness_start, "CWE476", "E", "NULL Pointer Dereference"); tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: BEFORE"); /* STONESOUP: CROSSOVER-POINT */ stonesoup_pFile = fopen(darsey_bastia,"r"); stonesoup_buffer[0] = 0; tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: AFTER"); tracepoint(stonesoup_trace, trace_point, "TRIGGER-POINT: BEFORE"); tracepoint(stonesoup_trace, variable_address, "stonesoup_pFile", stonesoup_pFile, "TRIGGER-STATE"); /* STONESOUP: TRIGGER-POINT (Null Pointer Dereference: Unchecked file read) */ fgets(stonesoup_buffer,79,stonesoup_pFile); stonesoup_printf(stonesoup_buffer); stonesoup_printf("\n"); fclose(stonesoup_pFile); tracepoint(stonesoup_trace, trace_point, "TRIGGER-POINT: AFTER"); tracepoint(stonesoup_trace, weakness_end); ; if (((char *)sintoc_kokowai) != 0) free(((char *)((char *)sintoc_kokowai))); stonesoup_close_printf_context(); }