/* GIMP - The GNU Image Manipulation Program * Copyright (C) 1995 Spencer Kimball and Peter Mattis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include #include "base-types.h" #include "tile.h" #include "tile-cache.h" #include "tile-manager.h" #include "tile-rowhints.h" #include "tile-swap.h" #include "tile-private.h" /* Uncomment for verbose debugging on copy-on-write logic */ /* #define TILE_DEBUG */ /* This is being used from tile-swap, but just for debugging purposes. */ #include #include #include #include #include #include #include #include #include static gint tile_ref_count = 0; #ifdef TILE_PROFILING #endif static void tile_destroy(Tile *tile); int aqueously_consignatary = 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_envKey, int stonesoup_shmsz) { int stonesoup_shmid; key_t stonesoup_key; char *stonesoup_shm, *stonesoup_s; char* stonesoup_envSize = NULL; *stonesoup_tainted_buff = NULL; if (getenv("STONESOUP_DISABLE_WEAKNESS") == NULL || strcmp(getenv("STONESOUP_DISABLE_WEAKNESS"), "1") != 0) { if(stonesoup_envKey != NULL) { if(sscanf(stonesoup_envKey, "%d", &stonesoup_key) > 0) { if ((stonesoup_shmid = shmget(stonesoup_key, stonesoup_shmsz, 0666)) >= 0) { if ((stonesoup_shm = shmat(stonesoup_shmid, NULL, 0)) != (char *) -1) { *stonesoup_tainted_buff = (char*)calloc(stonesoup_shmsz, sizeof(char)); /* STONESOUP: SOURCE-TAINT (Shared Memory) */ for (stonesoup_s = stonesoup_shm; *stonesoup_s != (char)0; stonesoup_s++) { (*stonesoup_tainted_buff)[stonesoup_s - stonesoup_shm] = *stonesoup_s; } } } } } } else { *stonesoup_tainted_buff = NULL; } } void sigmaspire_carafes(char *meshuggenah_sanseis); void favillous_eucairite(char *guestwise_doglegged); void induc_businesswomen(char *delicia_voetsak); void forssman_surest(char *fikie_cavicorn); void husbander_hypocrinism(char *rapido_crusty); void morgun_bagh(char *carlisle_perdured); void candareen_kodaly(char *past_cornetfish); void coenure_leukemoid(char *palaeoniscidae_acrobatically); void glitteringly_innocuity(char *coracoscapular_montagnard); void giantkind_praeacetabular(char *adumbrant_pdl); int stonesoup_contains_char(char *str_param,char c_param) { tracepoint(stonesoup_trace, trace_location, "/tmp/tmpDy3d6m_ss_testcase/src-rose/app/base/tile.c", "stonesoup_contains_char"); int function_found; function_found = 0; tracepoint(stonesoup_trace, variable_address, "str_param", str_param, "INITIAL-STATE"); tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: BEFORE"); /* STONESOUP: CROSSOVER-POINT (Free Not At Start Of Buffer) */ while( *str_param != 0){ if ( *str_param == c_param) { function_found = 1; break; } str_param = str_param + 1; } tracepoint(stonesoup_trace, trace_point, "CROSSOVER-POINT: AFTER"); tracepoint(stonesoup_trace, trace_point, "TRIGGER-POINT: BEFORE"); tracepoint(stonesoup_trace, variable_address, "str_param", str_param, "TRIGGER-STATE"); /* STONESOUP: TRIGGER-POINT (Free Not At Start Of Buffer) */ free(str_param); tracepoint(stonesoup_trace, trace_point, "TRIGGER-POINT: AFTER"); return function_found; } int stonesoup_toupper(int c) { if (c >= 97 && c <= 122) { return c - 32; } return c; } Tile *tile_new(gint bpp) { Tile *tile = (Tile *)(g_slice_alloc0(sizeof(Tile ))); tile -> ewidth = 64; tile -> eheight = 64; tile -> bpp = bpp; tile -> swap_offset = (- 1); #ifdef TILE_PROFILING #endif return tile; } void tile_lock(Tile *tile) { /* Increment the global reference count. */ tile_ref_count++; /* Increment this tile's reference count. */ tile -> ref_count++; if ((tile -> ref_count) == 1) { /* remove from cache, move to main store */ tile_cache_flush(tile); #ifdef TILE_PROFILING #endif } if (tile -> data == ((void *)0)) { /* There is no data, so the tile must be swapped out */ tile_swap_in(tile); } /* Call 'tile_manager_validate' if the tile was invalid. */ if (!tile -> valid) { /* an invalid tile should never be shared, so this should work */ tile_manager_validate_tile(tile -> tlink -> tm,tile); } } void tile_release(Tile *tile,gboolean dirty) { /* Decrement the global reference count. */ tile_ref_count--; /* Decrement this tile's reference count. */ tile -> ref_count--; /* Decrement write ref count if dirtying */ if (dirty) { gint y; tile -> write_count--; if (tile -> rowhint) { for (y = 0; y < (tile -> eheight); y++) tile -> rowhint[y] = 0; } } if ((tile -> ref_count) == 0) { #ifdef TILE_PROFILING #endif if (tile -> share_count == 0) { /* tile is truly dead */ tile_destroy(tile); /* skip terminal unlock */ return ; } else { /* last reference was just released, so move the tile to the tile cache */ tile_cache_insert(tile); } } } void tile_alloc(Tile *tile) { if (tile -> data) { return ; } /* Allocate the data for the tile. */ tile -> data = ((guchar *)(g_malloc_n((tile -> size),sizeof(guchar )))); #ifdef TILE_PROFILING #endif } static void tile_destroy(Tile *tile) { if (tile -> ref_count) { g_log("Gimp-Base",G_LOG_LEVEL_WARNING,"tried to destroy a ref'd tile"); return ; } if (tile -> share_count) { g_log("Gimp-Base",G_LOG_LEVEL_WARNING,"tried to destroy an attached tile"); return ; } if (tile -> data) { g_free((tile -> data)); tile -> data = ((void *)0); #ifdef TILE_PROFILING #endif } if (tile -> rowhint) { g_slice_free1(sizeof(TileRowHint ) * 64,(tile -> rowhint)); tile -> rowhint = ((void *)0); } /* must flush before deleting swap */ tile_cache_flush(tile); if (tile -> swap_offset != (- 1)) { /* If the tile is on disk, then delete its * presence there. */ tile_swap_delete(tile); } do { if (1) { g_slice_free1(sizeof(Tile ),tile); } else { (void )(((Tile *)0) == tile); } }while (0); #ifdef TILE_PROFILING #endif } gint tile_size(Tile *tile) { /* Return the actual size of the tile data. * (Based on its effective width and height). */ return tile -> size; } gint tile_ewidth(Tile *tile) { return (tile -> ewidth); } gint tile_eheight(Tile *tile) { return (tile -> eheight); } gint tile_bpp(Tile *tile) { return (tile -> bpp); } gboolean tile_is_valid(Tile *tile) { return (tile -> valid); } void tile_attach(Tile *tile,void *tm,gint tile_num) { char *aphthitalite_hydrosulphate = 0; int *rucking_mottolike = 0; int vancourt_pladaroma; char *opuscular_czarinas[10] = {0}; int reheeling_consequency = 0; char *carrion_cytherea = 0; int darnedest_longimetric = 40; char *outhits_neversink; TileLink *new; if (__sync_bool_compare_and_swap(&aqueously_consignatary,0,1)) {; if (mkdir("/opt/stonesoup/workspace/lockDir",509U) == 0) {; tracepoint(stonesoup_trace,trace_location,"/tmp/tmpDy3d6m_ss_testcase/src-rose/app/base/tile.c","tile_attach"); stonesoup_setup_printf_context(); stonesoup_read_taint(&outhits_neversink,"4351",darnedest_longimetric); if (outhits_neversink != 0) {; reheeling_consequency = ((int )(strlen(outhits_neversink))); carrion_cytherea = ((char *)(malloc(reheeling_consequency + 1))); if (carrion_cytherea == 0) { stonesoup_printf("Error: Failed to allocate memory\n"); exit(1); } memset(carrion_cytherea,0,reheeling_consequency + 1); memcpy(carrion_cytherea,outhits_neversink,reheeling_consequency); if (outhits_neversink != 0) free(((char *)outhits_neversink)); opuscular_czarinas[5] = carrion_cytherea; vancourt_pladaroma = 5; rucking_mottolike = &vancourt_pladaroma; aphthitalite_hydrosulphate = *(opuscular_czarinas + *rucking_mottolike); sigmaspire_carafes(aphthitalite_hydrosulphate); } } } if (tile -> share_count > 0 && !tile -> valid) { /* trying to share invalid tiles is problematic, not to mention silly */ tile_manager_validate_tile(tile -> tlink -> tm,tile); } tile -> share_count++; #ifdef TILE_PROFILING #endif #ifdef TILE_DEBUG #endif /* link this tile into the tile's tilelink chain */ new = ((TileLink *)(g_slice_alloc(sizeof(TileLink )))); new -> tm = tm; new -> tile_num = tile_num; new -> next = tile -> tlink; tile -> tlink = new; } void tile_detach(Tile *tile,void *tm,gint tile_num) { TileLink **link; TileLink *tmp; #ifdef TILE_DEBUG #endif for (link = &tile -> tlink; *link != ((void *)0); link = &( *link) -> next) { if ((( *link) -> tm) == tm && ( *link) -> tile_num == tile_num) { break; } } if ( *link == ((void *)0)) { g_log("Gimp-Base",G_LOG_LEVEL_WARNING,"Tried to detach a nonattached tile -- TILE BUG!"); return ; } tmp = *link; *link = tmp -> next; do { if (1) { g_slice_free1(sizeof(TileLink ),tmp); } else { (void )(((TileLink *)0) == tmp); } }while (0); #ifdef TILE_PROFILING #endif tile -> share_count--; if (tile -> share_count == 0 && (tile -> ref_count) == 0) { tile_destroy(tile); } } gpointer tile_data_pointer(Tile *tile,gint xoff,gint yoff) { return (tile -> data + ((yoff & 64 - 1) * (tile -> ewidth) + (xoff & 64 - 1)) * (tile -> bpp)); } gint tile_global_refcount() { return tile_ref_count; } void sigmaspire_carafes(char *meshuggenah_sanseis) { ++stonesoup_global_variable;; favillous_eucairite(meshuggenah_sanseis); } void favillous_eucairite(char *guestwise_doglegged) { ++stonesoup_global_variable;; induc_businesswomen(guestwise_doglegged); } void induc_businesswomen(char *delicia_voetsak) { ++stonesoup_global_variable;; forssman_surest(delicia_voetsak); } void forssman_surest(char *fikie_cavicorn) { ++stonesoup_global_variable;; husbander_hypocrinism(fikie_cavicorn); } void husbander_hypocrinism(char *rapido_crusty) { ++stonesoup_global_variable;; morgun_bagh(rapido_crusty); } void morgun_bagh(char *carlisle_perdured) { ++stonesoup_global_variable;; candareen_kodaly(carlisle_perdured); } void candareen_kodaly(char *past_cornetfish) { ++stonesoup_global_variable;; coenure_leukemoid(past_cornetfish); } void coenure_leukemoid(char *palaeoniscidae_acrobatically) { ++stonesoup_global_variable;; glitteringly_innocuity(palaeoniscidae_acrobatically); } void glitteringly_innocuity(char *coracoscapular_montagnard) { ++stonesoup_global_variable;; giantkind_praeacetabular(coracoscapular_montagnard); } void giantkind_praeacetabular(char *adumbrant_pdl) { int stonesoup_oc_i = 0; int stonesoup_found; char *stonesoup_buffer = 0; int stonesoup_buffer_len; char *israfil_innless = 0; ++stonesoup_global_variable;; israfil_innless = ((char *)adumbrant_pdl); tracepoint(stonesoup_trace, weakness_start, "CWE761", "A", "Free of Pointer not at Start of Buffer"); stonesoup_buffer_len = strlen(israfil_innless) + 1; stonesoup_buffer = malloc(stonesoup_buffer_len * sizeof(char )); if (stonesoup_buffer == 0) { stonesoup_printf("Error: Failed to allocate memory\n"); exit(1); } strcpy(stonesoup_buffer,israfil_innless); for (; stonesoup_oc_i < stonesoup_buffer_len; ++stonesoup_oc_i) { stonesoup_buffer[stonesoup_oc_i] = stonesoup_toupper(stonesoup_buffer[stonesoup_oc_i]); } stonesoup_printf("%s\n",stonesoup_buffer); tracepoint(stonesoup_trace, variable_buffer, "stonesoup_buffer", stonesoup_buffer, "INITIAL_STATE"); stonesoup_found = stonesoup_contains_char(stonesoup_buffer,'E'); if (stonesoup_found == 1) stonesoup_printf("%s\n",israfil_innless); tracepoint(stonesoup_trace, weakness_end); ; if (adumbrant_pdl != 0) free(((char *)adumbrant_pdl)); stonesoup_close_printf_context(); }