void goto_symext::symex_free(const expr2tc &expr)
{
  const code_free2t &code = to_code_free2t(expr);

  // Trigger 'free'-mode dereference of this pointer. Should generate various
  // dereference failure callbacks.
  expr2tc tmp = code.operand;
  dereference(tmp, false, true);

  address_of2tc addrof(code.operand->type, tmp);
  pointer_offset2tc ptr_offs(pointer_type2(), addrof);
  equality2tc eq(ptr_offs, zero_ulong);
  claim(eq, "Operand of free must have zero pointer offset");

  // Clear the alloc bit, and set the deallocated bit.
  guardt guard;
  type2tc sym_type = type2tc(new array_type2t(get_bool_type(),
                                              expr2tc(), true));
  pointer_object2tc ptr_obj(pointer_type2(), code.operand);

  symbol2tc dealloc_sym(sym_type, deallocd_arr_name);
  index2tc dealloc_index_expr(get_bool_type(), dealloc_sym, ptr_obj);
  expr2tc truth = true_expr;
  symex_assign_rec(dealloc_index_expr, truth, guard);

  symbol2tc valid_sym(sym_type, valid_ptr_arr_name);
  index2tc valid_index_expr(get_bool_type(), valid_sym, ptr_obj);
  expr2tc falsity = false_expr;
  symex_assign_rec(valid_index_expr, falsity, guard);
}
Exemple #2
0
void goto_symext::track_new_pointer(
  const expr2tc &ptr_obj,
  const type2tc &new_type,
  const expr2tc &size)
{
  // Also update all the accounting data.

  // Mark that object as being dynamic, in the __ESBMC_is_dynamic array
  type2tc sym_type =
    type2tc(new array_type2t(get_bool_type(), expr2tc(), true));
  symbol2tc sym(sym_type, dyn_info_arr_name);

  index2tc idx(get_bool_type(), sym, ptr_obj);
  expr2tc truth = gen_true_expr();
  symex_assign(code_assign2tc(idx, truth), true);

  symbol2tc valid_sym(sym_type, valid_ptr_arr_name);
  index2tc valid_index_expr(get_bool_type(), valid_sym, ptr_obj);
  truth = gen_true_expr();
  symex_assign(code_assign2tc(valid_index_expr, truth), true);

  symbol2tc dealloc_sym(sym_type, deallocd_arr_name);
  index2tc dealloc_index_expr(get_bool_type(), dealloc_sym, ptr_obj);
  expr2tc falseity = gen_false_expr();
  symex_assign(code_assign2tc(dealloc_index_expr, falseity), true);

  type2tc sz_sym_type =
    type2tc(new array_type2t(pointer_type2(), expr2tc(), true));
  symbol2tc sz_sym(sz_sym_type, alloc_size_arr_name);
  index2tc sz_index_expr(get_bool_type(), sz_sym, ptr_obj);

  expr2tc object_size_exp;
  if(is_nil_expr(size))
  {
    try
    {
      mp_integer object_size = type_byte_size(new_type);
      object_size_exp =
        constant_int2tc(pointer_type2(), object_size.to_ulong());
    }
    catch(array_type2t::dyn_sized_array_excp *e)
    {
      object_size_exp = typecast2tc(pointer_type2(), e->size);
    }
  }
  else
  {
    object_size_exp = size;
  }

  symex_assign(code_assign2tc(sz_index_expr, object_size_exp), true);
}
Exemple #3
0
void goto_symext::symex_free(const expr2tc &expr)
{
  const code_free2t &code = to_code_free2t(expr);

  // Trigger 'free'-mode dereference of this pointer. Should generate various
  // dereference failure callbacks.
  expr2tc tmp = code.operand;
  dereference(tmp, dereferencet::FREE);

  // Don't rely on the output of dereference in free mode; instead fetch all
  // the internal dereference state for pointed at objects, and creates claims
  // that if pointed at, their offset is zero.
  internal_deref_items.clear();
  tmp = code.operand;

  // Create temporary, dummy, dereference
  tmp = dereference2tc(get_uint8_type(), tmp);
  dereference(tmp, dereferencet::INTERNAL);

  // Only add assertions to check pointer offset if pointer check is enabled
  if(!options.get_bool_option("no-pointer-check"))
  {
    for(auto const &item : internal_deref_items)
    {
      guardt g = cur_state->guard;
      g.add(item.guard);
      expr2tc offset = item.offset;
      expr2tc eq = equality2tc(offset, gen_ulong(0));
      g.guard_expr(eq);
      claim(eq, "Operand of free must have zero pointer offset");
    }
  }

  // Clear the alloc bit, and set the deallocated bit.
  type2tc sym_type =
    type2tc(new array_type2t(get_bool_type(), expr2tc(), true));
  expr2tc ptr_obj = pointer_object2tc(pointer_type2(), code.operand);
  dereference(ptr_obj, dereferencet::READ);

  symbol2tc dealloc_sym(sym_type, deallocd_arr_name);
  index2tc dealloc_index_expr(get_bool_type(), dealloc_sym, ptr_obj);
  expr2tc truth = gen_true_expr();
  symex_assign(code_assign2tc(dealloc_index_expr, truth), true);

  symbol2tc valid_sym(sym_type, valid_ptr_arr_name);
  index2tc valid_index_expr(get_bool_type(), valid_sym, ptr_obj);
  expr2tc falsity = gen_false_expr();
  symex_assign(code_assign2tc(valid_index_expr, falsity), true);
}
void goto_symext::symex_free(const expr2tc &expr)
{
  const code_free2t &code = to_code_free2t(expr);

  // Trigger 'free'-mode dereference of this pointer. Should generate various
  // dereference failure callbacks.
  expr2tc tmp = code.operand;
  dereference(tmp, false, true);

  // Don't rely on the output of dereference in free mode; instead fetch all
  // the internal dereference state for pointed at objects, and creates claims
  // that if pointed at, their offset is zero.
  internal_deref_items.clear();
  tmp = code.operand;
  // Create temporary, dummy, dereference
  tmp = dereference2tc(get_uint8_type(), tmp);
  dereference(tmp, false, false, true); // 'internal' dereference
  for (const auto &item : internal_deref_items) {
    guardt g = cur_state->guard;
    g.add(item.guard);
    expr2tc offset = item.offset;
    expr2tc eq = equality2tc(offset, zero_ulong);
    g.guard_expr(eq);
    claim(eq, "Operand of free must have zero pointer offset");
  }

  // Clear the alloc bit, and set the deallocated bit.
  guardt guard;
  type2tc sym_type = type2tc(new array_type2t(get_bool_type(),
                                              expr2tc(), true));
  pointer_object2tc ptr_obj(pointer_type2(), code.operand);

  symbol2tc dealloc_sym(sym_type, deallocd_arr_name);
  index2tc dealloc_index_expr(get_bool_type(), dealloc_sym, ptr_obj);
  expr2tc truth = true_expr;
  symex_assign_rec(dealloc_index_expr, truth, guard);

  symbol2tc valid_sym(sym_type, valid_ptr_arr_name);
  index2tc valid_index_expr(get_bool_type(), valid_sym, ptr_obj);
  expr2tc falsity = false_expr;
  symex_assign_rec(valid_index_expr, falsity, guard);
}
Exemple #5
0
int main(int argc, char * argv[]) {
  char  query[1024];
  char	Sym[16];
  char	Price[16];
  char	Ticker[32];
  char	mail_msg[1024];
  char	ini_file[1024];
  char	errbuf[CURL_ERROR_SIZE];
  char	market_open[12]=MARKET_OPEN;
  char	market_close[12]=MARKET_CLOSE;
  char 	*saveptr;
  int	x;
  float	StopPrice=FLT_MAX;
  float	cur_price=0.0;
  CURL *curl;
  CURLcode	res=0;
  MYSQL_RES *result;
  MYSQL_ROW row;
  time_t t;
  struct tm *TM=0;
  dictionary *d;

  // parse cli parms
  if (argc < 3) Usage(argv[0]);
  // set up variables
  memset(query,0,sizeof(query));
  memset(Ticker,0,sizeof(Ticker));
  memset(Sym,0,sizeof(Sym));
  for (x=0;x<strlen(argv[1]);x++) Sym[x]=toupper(argv[1][x]);
  StopPrice = strtof(argv[2],NULL);
  // initialize CURL
  if ((chunk.memory = calloc(1,1)) == NULL) {
    fprintf(stderr,"calloc failed, aborting process\n");
    exit(EXIT_FAILURE);
  }    
  curl_global_init(CURL_GLOBAL_NOTHING);
  curl=curl_easy_init();
  if(!curl) {
    fprintf(stderr,"curl init failed, aborting process\n");
    exit(EXIT_FAILURE);
  }
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ParseData);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
  curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);
  curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 0);

  #include "Includes/beancounter-conn.inc"
  valid_sym(Sym);

  // get exchange for Sym
  sprintf(query,"select trim(exchange) from stockinfo where symbol = \"%s\"",Sym);
  if (mysql_query(mysql,query)) print_error(mysql, "Failed to query database");
  if ((result=mysql_store_result(mysql)) == NULL) print_error(mysql, "store_results failed"); 
  row=mysql_fetch_row(result);
  sprintf(Ticker,"%s:%s",row[0],Sym);
  if (DEBUG) printf("%s\n",Ticker);
  // finished with the database
  mysql_free_result(result);
  #include "Includes/mysql-disconn.inc"
  
  sprintf(query,"http://www.google.com/finance?q=%s",Ticker);
  curl_easy_setopt(curl, CURLOPT_URL, query);
  
  // Loop while price is less than target
  if (DEBUG) printf("Monitoring price for %s\n",Sym);
  do {
    // check the time
    t = time(NULL);
    if ((TM = localtime(&t)) == NULL) { perror("localtime"); exit(EXIT_FAILURE); }
    if (TM->tm_hour>strtoul(market_close,&saveptr,10) || 
      (TM->tm_hour==strtoul(market_close,&saveptr,10) && TM->tm_min>(strtoul(saveptr+1,NULL,10)+(SLEEP_INTERVAL/60)))) {
      // market is closed for the day
      printf("Stock market is closed for the day (after %s)\n",market_close);
      exit(EXIT_FAILURE);
    }
    if (TM->tm_hour<strtoul(market_open,&saveptr,10) || 
      (TM->tm_hour==strtoul(market_open,&saveptr,10) && TM->tm_min<strtoul(saveptr+1,NULL,10))) {
      printf("Stock market not open yet, sleeping until %s\n",market_open);
      sleep((strtoul(market_open,&saveptr,10)-TM->tm_hour)*3600);
      while (atoi(saveptr+1)>TM->tm_min) {
        sleep(SLEEP_INTERVAL);
        t = time(NULL);
        if ((TM = localtime(&t)) == NULL) { perror("localtime"); exit(EXIT_FAILURE); }
        x=strtoul(market_open,&saveptr,10);
      }
    } 
    // download current price
    chunk.size = 0;
    res=curl_easy_perform(curl);
    if (res) {	// 0 means no errors
      if (res != 56 && res != 28) {
	printf("01 Error %d Unable to access the internet\n",res);
	printf("%s\n",errbuf);
	exit(EXIT_FAILURE);
      } else {	// retry
	sleep(SLEEP_INTERVAL);
	continue;
      }
    }
    // was any data returned?
    if (strstr(chunk.memory,"404 Not Found")) {     
      printf("%s not found\n",Sym);
      curl_easy_cleanup(curl);
      free(chunk.memory);
      exit(EXIT_FAILURE);
    }
    if (chunk.size == 0) {
//      printf("Error receiving data for %s, retrying\n",Sym);
      sleep(SLEEP_INTERVAL);
      continue;
    }
    // do the token parsing here
    if ((saveptr = strstr(chunk.memory,"<span class=\"pr\">")) == NULL) {
//      printf("Error parsing data for %s, retrying\n",Sym);
      sleep(SLEEP_INTERVAL);
      continue;
    }
    saveptr += strlen("<span class=\"pr\">")+1;
    saveptr = strchr(saveptr,'>')+1;	// should now be pointing at the current price
    memset(Price,0,sizeof(Price));
    strncpy(Price,saveptr,(strchr(saveptr,'<'))-saveptr);
    cur_price = strtof(Price,NULL);
    if (DEBUG) printf("cur_price: %.2f\n",cur_price);
    if (DEBUG) printf("Pausing for %d seconds\n",SLEEP_INTERVAL);
    if (cur_price <= StopPrice) break;
    sleep(SLEEP_INTERVAL);
  } while(cur_price >= StopPrice);
  // end While loop
  curl_easy_cleanup(curl);
  free(chunk.memory);

  // process the output message
  sprintf(ini_file, "%s/%s", getenv("HOME"), INIFILE);
  d = iniparser_load(ini_file);
  if (d==NULL) {
    puts("INI file not opened, aborting");
    exit(EXIT_FAILURE);
  }
  sprintf(query,"Sell %s at %.2f stoploss price",Sym,cur_price);
  printf("%s\n",query);
  if (iniparser_find_entry(d, "Dest:email")) {
    sprintf(mail_msg,"echo %s |mailx -s \"%s\" %s",query,query, iniparser_getstring(d, "Dest:email", "null"));
    system(mail_msg);
  }
  if (iniparser_find_entry(d, "Dest:sms")) {
    sprintf(mail_msg,"echo %s |mailx -s \"%s\" %s",query,query, iniparser_getstring(d, "Dest:sms", "null"));
    system(mail_msg);
  } 
  iniparser_freedict(d);    
  exit(EXIT_SUCCESS);
}