bool AuthorizationSet::DeserializeElementsData(const uint8_t** buf_ptr, const uint8_t* end) {
    uint32_t elements_count;
    uint32_t elements_size;
    if (!copy_uint32_from_buf(buf_ptr, end, &elements_count) ||
        !copy_uint32_from_buf(buf_ptr, end, &elements_size)) {
        set_invalid(MALFORMED_DATA);
        return false;
    }

    // Note that the following validation of elements_count is weak, but it prevents allocation of
    // elems_ arrays which are clearly too large to be reasonable.
    if (static_cast<ptrdiff_t>(elements_size) > end - *buf_ptr ||
        elements_count * sizeof(uint32_t) > elements_size) {
        set_invalid(MALFORMED_DATA);
        return false;
    }

    if (!reserve_elems(elements_count))
        return false;

    uint8_t* indirect_end = indirect_data_ + indirect_data_size_;
    const uint8_t* elements_end = *buf_ptr + elements_size;
    for (size_t i = 0; i < elements_count; ++i) {
        if (!deserialize(elems_ + i, buf_ptr, elements_end, indirect_data_, indirect_end)) {
            set_invalid(MALFORMED_DATA);
            return false;
        }
    }
    elems_size_ = elements_count;
    return true;
}
예제 #2
0
void snapshot_var_t::update_impl() {
    ref_t<pi_ext_t> parsed;
    try {
        in_t::ptr_t p(value_string_);
        parsed = pi_ext_t::parse(p, &pi_t::parse_text);
    } catch(const pi_t::exception_t& ex) {
        ex.log();
    } catch(const exception_t& ex) {
        ex.log();
    }

    if(parsed == NULL) {
        MKCSTR(value_z, value_string_);
        log_warning("snapshot_var_t parse(%s) failed", value_z);
        set_invalid();
        return;
    }

    const pi_t& pi = parsed->pi();
    snapshot_version_ = pi.s_ind(0).s_uint();
    str_t location_str = pi.s_ind(1).s_str();
    location_ = string_t::ctor_t(location_str.size())(location_str);

    if(snapshot_version_ == 0 || location_.size() == 0) {
        MKCSTR(value_z, value_string_);
        log_warning("snapshot_var_t parse(%s) failed", value_z);
        set_invalid();
        return;
    }

    valid_ = true;
    MKCSTR(location_z, location_);
    log_debug("snapshot_var_t updated to (%ld, %s)", snapshot_version_, location_z);
}
예제 #3
0
파일: oid.cpp 프로젝트: asir6/Colt
//=============[Oid::Oid( const char *dotted_string ]=====================
// constructor using a dotted string
//
// do a string to oid using the string passed in
Oid::Oid( const char * dotted_oid_string, size_t size)
{
  // can't init enum SmiValue so just memset it clean
  set_null();

  size_t z;
  if ((z = ACE_OS::strlen(dotted_oid_string)) == 0) {
    set_invalid();
    return;
  }

  if (size == (unsigned int)-1)
    size = z;
  if (size > z)
    size = z;

  char *ptr = (char *)dotted_oid_string;;
  if (size < z) {
    // create new buffer if needed
    ACE_NEW(ptr, char [size]);

    // sz should be in StrToOid?
    ACE_OS::memcpy( (void *)ptr, dotted_oid_string, size);
  }

  size_t byte_counter;
  if (StrToOid( (char *) ptr, &smival.value.oid, byte_counter) < 0)
    set_invalid();
  if (ptr != dotted_oid_string)
    delete [] ptr;
}
예제 #4
0
파일: oid.cpp 프로젝트: asir6/Colt
//==============[Oid:: operator += const char *a ]=========================
// append operator, appends a string
//
// allocate some space for a max oid string
// extract current string into space
// concat new string
// free up existing oid
// make a new oid from string
// delete allocated space
Oid& Oid::operator+=( const char *a)
{
  unsigned long n;

  if (!a)
    return *this;

  if ( *a=='.')
    a++;
  size_t sz = ACE_OS::strlen(a);

  if (valid()) {
    n = (smival.value.oid.len *SNMPCHARSIZE) + smival.value.oid.len + 1 + sz;
    char *ptr;
    ACE_NEW_RETURN(ptr, char[ n], *this);
    size_t byte_counter;
    if (OidToStr(&smival.value.oid, n,ptr, byte_counter) > 0) {
        delete [] ptr;
        set_invalid();
        return *this;
      }

   if (ACE_OS::strlen(ptr))
     ACE_OS::strcat(ptr,".");
   ACE_OS::strcat(ptr,a);
   if ( smival.value.oid.len !=0) {
     set_invalid();
    }

   if (StrToOid( (char *) ptr, &smival.value.oid, byte_counter) < 0) {
       set_invalid();
   }
   delete [] ptr;
  }
  else {
예제 #5
0
파일: oid.cpp 프로젝트: asir6/Colt
//=============[Oid::operator = const char * dotted_string ]==============
// assignment to a string operator overloaded
//
// free the existing oid
// create the new oid from the string
// return this object
void Oid::set_data( const char *dotted_oid_string)
{
  // delete the old value
  if ( smival.value.oid.ptr ) {
    set_invalid();
  }

  // assign the new value
  size_t byte_counter;
  if (StrToOid( (char *) dotted_oid_string, &smival.value.oid, byte_counter) <0)
    set_invalid();
}
bool AuthorizationSet::DeserializeIndirectData(const uint8_t** buf_ptr, const uint8_t* end) {
    UniquePtr<uint8_t[]> indirect_buf;
    if (!copy_size_and_data_from_buf(buf_ptr, end, &indirect_data_size_, &indirect_buf)) {
        set_invalid(MALFORMED_DATA);
        return false;
    }
    indirect_data_ = indirect_buf.release();
    return true;
}
예제 #7
0
파일: oid.cpp 프로젝트: asir6/Colt
//=============[Oid::~Oid]==============================================
// destructor
//
// free up the descriptor space
Oid::~Oid()
{
  // free up the octet deep memory
  if ( smival.value.oid.ptr ) {
    set_invalid();
  }

  // free up the output string
  if ( iv_str != 0)
    delete [] iv_str;
}
예제 #8
0
파일: disk.c 프로젝트: joshsyu/PQEMU
// IBM/MS extended media change
static void
disk_1349(struct bregs *regs, struct drive_s *drive_g)
{
    if (regs->dl < EXTSTART_CD) {
        // Always success for HD
        disk_ret(regs, DISK_RET_SUCCESS);
        return;
    }
    set_invalid(regs);
    // always send changed ??
    regs->ah = DISK_RET_ECHANGED;
}
bool AuthorizationSet::Deserialize(const uint8_t** buf_ptr, const uint8_t* end) {
    FreeData();

    if (!DeserializeIndirectData(buf_ptr, end) || !DeserializeElementsData(buf_ptr, end))
        return false;

    if (indirect_data_size_ != ComputeIndirectDataSize(elems_, elems_size_)) {
        set_invalid(MALFORMED_DATA);
        return false;
    }
    return true;
}
예제 #10
0
파일: oid.cpp 프로젝트: asir6/Colt
//=============[Oid::Oid( const unsigned long *raw_oid, int oid_len) ]====
// constructor using raw numeric form
//
// copy the integer values into the private member
Oid::Oid(const unsigned long *raw_oid, size_t oid_len)
{
  set_null();

  smival.syntax = sNMP_SYNTAX_OID;
  set_invalid();

  if (raw_oid && oid_len > 0) {
    ACE_NEW(smival.value.oid.ptr, SmiUINT32[ oid_len]);
    smival.value.oid.len = oid_len;
    for (size_t i=0; i < oid_len; i++)
      smival.value.oid.ptr[i] = raw_oid[i];
  }
}
예제 #11
0
파일: oid.cpp 프로젝트: asir6/Colt
//=============[Oid:: operator = const Oid &oid ]==========================
// assignment to another oid object overloaded
//
// free the existing oid
// create a new one from the object passed in
// TODO: measure perf vs memory of no realloc in case where len >= oid.len
Oid& Oid::operator=( const Oid &oid)
{
  // protect against assignment from self
  if ( this == &oid)
      return *this;

  set_invalid();

  // check for zero len on source
  if ( oid.smival.value.oid.len == 0)
     return *this;

  const SmiLPOID srcOid = (SmiLPOID) &(oid.smival.value.oid);
  init_value(srcOid, oid.smival.value.oid.len);
  return *this;
}
예제 #12
0
void ic3_engine::push_current_frame() {

  // Search while we have something to do
  while (!d_induction_obligations.empty() && !d_property_invalid) {

    // Pick a formula to try and prove inductive, i.e. that F_k & P & T => P'
    induction_obligation ind = pop_induction_obligation();

    // If formula is marked as invalid, skip it
    if (is_invalid(ind.formula)) {
      continue;
    }

    // Push the formula forward if it's inductive at the frame
    induction_result ind_result = push_if_inductive(ind);

    // See what happened
    switch (ind_result) {
    case INDUCTION_RETRY:
      // We'll retry the same formula (it's already added to the solver)
      enqueue_induction_obligation(ind);
      break;
    case INDUCTION_SUCCESS:
      // Boss
      break;
    case INDUCTION_FAIL: {
      // Not inductive, mark it
      const reachability::cex_type& cex = d_reachability.get_cex();
      assert(cex.size() > 0);
      assert(cex.size() - 1 <= d_induction_frame_index);
      size_t cex_frame = cex.size() - 1 + d_induction_frame_depth;
      set_invalid(ind.formula, cex_frame);
      d_induction_frame_index_next = std::min(d_induction_frame_index_next, cex_frame);
      // Try to extend the counter-example further
      extend_induction_failure(ind.formula);
      break;
    }
    case INDUCTION_INCONCLUSIVE:
      break;
    }
  }

  // Dump dependency graph if asked
  if (ctx().get_options().get_bool("ic3-dump-dependencies")) {
    dump_dependencies();
  }
}
bool AuthorizationSet::reserve_elems(size_t count) {
    if (is_valid() != OK)
        return false;

    if (count >= elems_capacity_) {
        keymaster_key_param_t* new_elems = new keymaster_key_param_t[count];
        if (new_elems == NULL) {
            set_invalid(ALLOCATION_FAILURE);
            return false;
        }
        memcpy(new_elems, elems_, sizeof(*elems_) * elems_size_);
        delete[] elems_;
        elems_ = new_elems;
        elems_capacity_ = count;
    }
    return true;
}
bool AuthorizationSet::reserve_indirect(size_t length) {
    if (is_valid() != OK)
        return false;

    if (length > indirect_data_capacity_) {
        uint8_t* new_data = new uint8_t[length];
        if (new_data == NULL) {
            set_invalid(ALLOCATION_FAILURE);
            return false;
        }
        memcpy(new_data, indirect_data_, indirect_data_size_);

        // Fix up the data pointers to point into the new region.
        for (size_t i = 0; i < elems_size_; ++i) {
            if (is_blob_tag(elems_[i].tag))
                elems_[i].blob.data = new_data + (elems_[i].blob.data - indirect_data_);
        }
        delete[] indirect_data_;
        indirect_data_ = new_data;
        indirect_data_capacity_ = length;
    }
    return true;
}
예제 #15
0
unsigned int gapmis_one_to_many_opt_gpu ( const char * p1, const char ** t, const struct gapmis_params * in, struct gapmis_align * out )
{
	const char * p[] = { p1, NULL};

	if ( in -> scoring_matrix > 1 )
	{
		errno = MATRIX;
		return ( 0 );
	}

	unsigned int 	pats = get_number_of_sequences (p);
	unsigned int 	txts = get_number_of_sequences (t);
	unsigned int	maxPatLen = get_max_length (pats, p);
	unsigned int	minTxtLen = get_min_length (txts, t);

	if (check_sequences(pats,p,in->scoring_matrix)==0)
	{
		errno = BADCHAR;
      		return ( 0 );
	}

	if (check_sequences(txts,t,in->scoring_matrix)==0)
	{
		errno = BADCHAR;
      		return ( 0 );
	}

	if(maxPatLen > minTxtLen)
	{
		errno = LENGTH;
      		return ( 0 );
	}

	if ( in -> max_gap >= minTxtLen )
	{
		errno = MAXGAP; 
		return ( 0 );
	}

	int err = -1;

	/* get the GPU id */
	cl_platform_id gpu_id = get_gpu_id(&err);	
	if(err)
	{	
	 	errno = NOGPU;
      		return ( 0 );
	}

        /* get the device id */
	cl_device_id dev_id = get_dev_id(gpu_id, &err);
	if(err)
	{	
	 	errno = NOGPU;
      		return ( 0 );
	}

	/* create the context using dev_id */
	cl_context context = create_context(dev_id, &err);
	if(err)
	{	
	 	errno = GPUERROR;
      		return ( 0 );
	}

	/* create a list with the commands to be executed by GPU */
	cl_command_queue cmd_queue = create_cmd_queue (dev_id, context, &err);
	if(err)
	{	
	 	errno = GPUERROR;
      		return ( 0 );
	}

	/* create a kernel */
	cl_kernel kernel;

	/* load the kernel ``kernel_dna.cl'' with name ``gapmis_kernel''*/
	if(in->scoring_matrix==0)
		kernel = load_kernel ("kernel_dna.cl", "gapmis_kernel", dev_id, context, &err);
	else
		kernel = load_kernel ("kernel_pro.cl", "gapmis_kernel", dev_id, context, &err);

	if(err)
	{	
	 	errno = KERNEL;
      		return ( 0 );
	}

	const unsigned int patGroupSize = 1;
	const unsigned int txtGroupSize = 768;
	unsigned int i, j;	
	unsigned int patGroups = get_number_of_groups (pats, patGroupSize);
	unsigned int txtGroups = get_number_of_groups (txts, txtGroupSize);	

	const char * groupPatterns[patGroupSize+1];
	set_null (groupPatterns, patGroupSize+1);

	const char * groupTexts[txtGroupSize+1];
	set_null (groupTexts, txtGroupSize+1);

	float * groupScores;
        groupScores = calloc (patGroupSize*txtGroupSize, sizeof(float) );

	int groupMatch [patGroupSize];
	float groupMatchScores [patGroupSize];
	set_invalid(groupMatch,patGroupSize);
	set_minimum(groupMatchScores,patGroupSize);	

	for(i=0;i<patGroups;i++)
	{
		set_null (groupPatterns, patGroupSize+1);
		initialize_pointers (groupPatterns,i,patGroupSize,p,pats);
		set_invalid(groupMatch,patGroupSize);
		set_minimum(groupMatchScores,patGroupSize);
		
		for(j=0;j<txtGroups;j++)
		{			
			set_null (groupTexts, txtGroupSize+1);
			initialize_pointers (groupTexts,j,txtGroupSize,t,txts);

			if( ! ( kernel_launch (kernel, context, cmd_queue, groupPatterns, groupTexts, in, groupScores) ))
				return ( 0 );			

			update_group_match (groupScores,groupMatch,groupMatchScores,patGroupSize,txtGroupSize, pats, txts, i, j);
		
		}

		for(j=0;j<patGroupSize;j++)
		{
			if(i*patGroupSize+j<pats)
			{
				groupPatterns[0] = p[i*patGroupSize+j];
				groupPatterns[1] = NULL;

				groupTexts[0] = t[groupMatch[j]];
				groupTexts[1] = NULL;
				
				if( !( kernel_launch_l (kernel, context, cmd_queue, groupPatterns, groupTexts, in, groupScores,&out[i*patGroupSize+j] ) ) )
					return ( 0 );				
			}
		}
	}

        free ( groupScores );
        clReleaseContext ( context );
	clReleaseCommandQueue ( cmd_queue );
        clReleaseKernel(kernel);

	return ( 1 );
 }
예제 #16
0
void ic3_engine::extend_induction_failure(expr::term_ref f) {

  const reachability::cex_type& cex = d_reachability.get_cex();

  assert(cex.size() > 0);
  //                                  !F
  //                         depth     |
  //       cex          ****************
  // *******************       |      |
  // .......................................................
  //                   G       |      |
  // !G!G          !G!G        |      |
  // FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  //                           |
  //                         frame

  // We have a counter-example to inductiveness of f at frame cex_depth + induction_size
  // and cex d_counterexample has its generalization at the back.
  assert(cex.size() - 1 + d_induction_frame_depth > d_induction_frame_index);

  // Solver for checking
  smt::solver_scope solver_scope;
  d_smt->ensure_counterexample_solver_depth(d_induction_frame_index+1); // Smalleet depth needed
  d_smt->get_counterexample_solver(solver_scope);
  solver_scope.push();
  smt::solver* solver = solver_scope.get_solver();

  assert(cex.size() - 1 <= d_smt->get_counterexample_solver_depth());

  // Assert all the generalizations
  size_t k = 0;
  for (; k < cex.size(); ++ k) {
    // Add the generalization to frame k
    expr::term_ref G_k = d_trace->get_state_formula(cex[k], k);
    solver->add(G_k, smt::solver::CLASS_A);
  }

  // Move to where f is false
  k = cex.size() - 1 + d_induction_frame_depth;

  // Assert f at next frame
  d_smt->ensure_counterexample_solver_depth(k);
  solver->add(d_trace->get_state_formula(tm().mk_term(expr::TERM_NOT, f), k), smt::solver::CLASS_A);

  // Should be SAT
  smt::solver::result r = solver->check();
  assert(r == smt::solver::SAT);
  expr::model::ref model = solver->get_model();
  d_trace->set_model(model, k+1);

  if (ctx().get_options().get_bool("ic3-dont-extend")) {
    return;
  }

  // Try to extend it
  for (;;) {

    // We know there is a counterexample to induction of f: 0, ..., k-1, with f
    // being false at k. We try to extend it to falsify the reason we
    // introduced f. We introduced f to refute the counterexample to induction
    // of parent(f), which is witnessed by generalization refutes(f). We are
    // therefore looking to satisfy refutes(f) at k.
    assert(is_invalid(f));

    d_stats.max_cex_depth->get_value() = std::max((int) k, d_stats.max_cex_depth->get_value());

    // Bump the assertion
    bump_induction_obligation(f, 1);

    // If no more parents, we're done
    if (!has_parent(f)) {
      // If this is a counter-example to the property itself => full counterexample
      if (d_properties.find(f) != d_properties.end()) {
        MSG(1) << "ic3: CEX found at depth " << d_smt->get_counterexample_solver_depth() << " (with induction frame at " << d_induction_frame_index << ")" << std::endl;
      }
      break;
    }

    // Try to extend
    k = k + get_refutes_depth(f);
    f = get_parent(f);

    // If invalid already, done
    if (is_invalid(f)) {
      break;
    }

    // Check at frame of the parent
    d_smt->ensure_counterexample_solver_depth(k);
    solver->add(d_trace->get_state_formula(tm().mk_term(expr::TERM_NOT, f), k), smt::solver::CLASS_A);

    // If not a generalization we need to check
    r = solver->check();

    // If not sat, we can't extend any more
    if (r != smt::solver::SAT) {
      break;
    }

    // We're sat (either by knowing, or by checking), so we extend further
    set_invalid(f, k);
    model = solver->get_model();
    d_trace->set_model(model, k+1);
  }
}