static int np_size_t(char *p, PyObject *v, const formatdef *f) { size_t x; if (get_size_t(v, &x) < 0) return -1; memcpy(p, (char *)&x, sizeof x); return 0; }
size_t Sqlite3_Database::row_count(const std::string& table_name) { auto stmt = new_statement("select count(*) from " + table_name); if(stmt->step()) return stmt->get_size_t(0); else throw SQL_DB_Error("Querying size of table " + table_name + " failed"); }
int flag_u(t_string *string, int i) { if (!ft_strncmp(string->converter.type, "ll", 2)) conv_ll(string, get_ulong_long_int(string)); else if (!ft_strncmp(string->converter.type, "l", 1)) conv_l(string, get_ulong_int(string)); else if (!ft_strncmp(string->converter.type, "hh", 2)) conv_hh(string, (unsigned char)get_uint(string)); else if (!ft_strncmp(string->converter.type, "h", 1)) conv_h(string, get_ushort(string)); else if (!ft_strncmp(string->converter.type, "z", 1)) conv_z(string, get_size_t(string)); else if (!ft_strncmp(string->converter.type, "j", 1)) conv_j(string, get_intmax_t(string)); else conv_default(string, get_uint(string)); return (i + 1); }
void Flag::print_as_flag(outputStream* st) { if (is_bool()) { st->print("-XX:%s%s", get_bool() ? "+" : "-", _name); } else if (is_int()) { st->print("-XX:%s=%d", _name, get_int()); } else if (is_uint()) { st->print("-XX:%s=%u", _name, get_uint()); } else if (is_intx()) { st->print("-XX:%s=" INTX_FORMAT, _name, get_intx()); } else if (is_uintx()) { st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx()); } else if (is_uint64_t()) { st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t()); } else if (is_size_t()) { st->print("-XX:%s=" SIZE_FORMAT, _name, get_size_t()); } else if (is_double()) { st->print("-XX:%s=%f", _name, get_double()); } else if (is_ccstr()) { st->print("-XX:%s=", _name); const char* cp = get_ccstr(); if (cp != NULL) { // Need to turn embedded '\n's back into separate arguments // Not so efficient to print one character at a time, // but the choice is to do the transformation to a buffer // and print that. And this need not be efficient. for (; *cp != '\0'; cp += 1) { switch (*cp) { default: st->print("%c", *cp); break; case '\n': st->print(" -XX:%s=", _name); break; } } } } else { ShouldNotReachHere(); } }
std::vector<X509_CRL> Certificate_Store_In_SQL::generate_crls() const { auto stmt = m_database->new_statement( "SELECT certificate,reason,time FROM " + m_prefix + "revoked " "JOIN " + m_prefix + "certificates ON " + m_prefix + "certificates.fingerprint == " + m_prefix + "revoked.fingerprint"); std::map<X509_DN,std::vector<CRL_Entry>> crls; while(stmt->step()) { auto blob = stmt->get_blob(0); auto cert = X509_Certificate( std::vector<uint8_t>(blob.first,blob.first + blob.second)); auto code = static_cast<CRL_Code>(stmt->get_size_t(1)); auto ent = CRL_Entry(cert,code); auto i = crls.find(cert.issuer_dn()); if(i == crls.end()) { crls.insert(std::make_pair(cert.issuer_dn(),std::vector<CRL_Entry>({ent}))); } else { i->second.push_back(ent); } } std::vector<X509_CRL> ret; X509_Time t(std::chrono::system_clock::now()); for(auto p: crls) { ret.push_back(X509_CRL(p.first,t,t,p.second)); } return ret; }
static AVP_dword DATA_PARAM ReadPropertyItem( Serialize* sz, AVP_byte type, void* val ) { AVP_word size; AVP_byte tmp; AVP_Bin_Item* v; switch( type ) { case avpt_nothing : return 1; // Byte-sized types case avpt_char : case avpt_byte : case avpt_group : return get_byte(sz, (AVP_byte *) val); case avpt_bool : size = (AVP_word)get_byte( sz, &tmp); *(AVP_bool *)val = tmp; return size; // Word-sized types case avpt_wchar : case avpt_short : case avpt_word : return get_word(sz, (AVP_word *) val); // Dword-sized types case avpt_long : case avpt_dword : case avpt_int : case avpt_uint : return get_dword( sz, (AVP_dword*)val ); // QWord-sized types case avpt_qword : case avpt_longlong: return get_qword( sz, (AVP_qword*)val ); // size_t-sized types case avpt_size_t : return get_size_t( sz, (AVP_size_t*)val ); // Custom structures case avpt_date : return get_date(sz, (AVP_date *)val); case avpt_time : return get_time(sz, (AVP_time *)val); case avpt_datetime: return get_datetime(sz, (AVP_datetime *) val); // String case avpt_str : if ( get_word( sz, &size) == sizeof(size) ) { if ( size != USHRT_MAX ) { AVP_char * ptr = allocator( size + sizeof(AVP_char) ); _ASSERT( ptr ); *(AVP_char **)val = ptr; if ( get_bytes(sz,ptr,size) == size ) { ptr[size] = 0; return sizeof(size) + size; } else { ptr[0] = 0; return 0; } } else return sizeof(size); } else return 0; // Windows unicode string case avpt_wstr : if ( get_word( sz, &size) == sizeof(size) ) { if ( size != USHRT_MAX ) { AVP_wchar * ptr = allocator( size + sizeof(AVP_wchar) ); _ASSERT( ptr ); *(AVP_wchar **)val = ptr; if ( get_bytes(sz,ptr,size) == size ) { ptr[size/sizeof(AVP_wchar)] = 0; convert_wchar_string ((wchar_t*) ptr); return sizeof(size) + size; } else { ptr[0] = 0; return 0; } } else return sizeof(size); } else return 0; case avpt_bin : v = val; v->size = 0; if ( get_word( sz, &size) == sizeof(size) ) { v->size = size; if ( v->size ) { v->data = allocator( v->size ); _ASSERT( v->data ); } else v->data = 0; if ( !v->size || (get_bytes(sz,v->data,v->size) == v->size) ) return sizeof(v->size) + v->size; else return 0; } else return 0; default : _RPT0( _CRT_ASSERT, "Bad property type" ); return 0; } return size ? size + sizeof(AVP_Property) : 0; }
Session_Manager_SQL::Session_Manager_SQL(std::shared_ptr<SQL_Database> db, const std::string& passphrase, RandomNumberGenerator& rng, size_t max_sessions, std::chrono::seconds session_lifetime) : m_db(db), m_rng(rng), m_max_sessions(max_sessions), m_session_lifetime(session_lifetime) { m_db->create_table( "create table if not exists tls_sessions " "(" "session_id TEXT PRIMARY KEY, " "session_start INTEGER, " "hostname TEXT, " "hostport INTEGER, " "session BLOB" ")"); m_db->create_table( "create table if not exists tls_sessions_metadata " "(" "passphrase_salt BLOB, " "passphrase_iterations INTEGER, " "passphrase_check INTEGER " ")"); const size_t salts = m_db->row_count("tls_sessions_metadata"); if(salts == 1) { // existing db auto stmt = m_db->new_statement("select * from tls_sessions_metadata"); if(stmt->step()) { std::pair<const byte*, size_t> salt = stmt->get_blob(0); const size_t iterations = stmt->get_size_t(1); const size_t check_val_db = stmt->get_size_t(2); size_t check_val_created; m_session_key = derive_key(passphrase, salt.first, salt.second, iterations, check_val_created); if(check_val_created != check_val_db) throw std::runtime_error("Session database password not valid"); } } else { // maybe just zap the salts + sessions tables in this case? if(salts != 0) throw std::runtime_error("Seemingly corrupted database, multiple salts found"); // new database case std::vector<byte> salt = unlock(rng.random_vec(16)); const size_t iterations = 256 * 1024; size_t check_val = 0; m_session_key = derive_key(passphrase, salt.data(), salt.size(), iterations, check_val); auto stmt = m_db->new_statement("insert into tls_sessions_metadata values(?1, ?2, ?3)"); stmt->bind(1, salt); stmt->bind(2, iterations); stmt->bind(3, check_val); stmt->spin(); } }
size_t Mt19937Random::get_size_t() const { return get_size_t(0, std::numeric_limits<std::size_t>::max()); }
void Flag::print_on(outputStream* st, bool withComments, bool printRanges) { // Don't print notproduct and develop flags in a product build. if (is_constant_in_binary()) { return; } if (!printRanges) { st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' ')); if (is_bool()) { st->print("%-16s", get_bool() ? "true" : "false"); } else if (is_int()) { st->print("%-16d", get_int()); } else if (is_uint()) { st->print("%-16u", get_uint()); } else if (is_intx()) { st->print(INTX_FORMAT_W(-16), get_intx()); } else if (is_uintx()) { st->print(UINTX_FORMAT_W(-16), get_uintx()); } else if (is_uint64_t()) { st->print(UINT64_FORMAT_W(-16), get_uint64_t()); } else if (is_size_t()) { st->print(SIZE_FORMAT_W(-16), get_size_t()); } else if (is_double()) { st->print("%-16f", get_double()); } else if (is_ccstr()) { const char* cp = get_ccstr(); if (cp != NULL) { const char* eol; while ((eol = strchr(cp, '\n')) != NULL) { size_t llen = pointer_delta(eol, cp, sizeof(char)); st->print("%.*s", (int)llen, cp); st->cr(); cp = eol+1; st->print("%5s %-35s += ", "", _name); } st->print("%-16s", cp); } else st->print("%-16s", ""); } st->print("%-20s", " "); print_kind(st); #ifndef PRODUCT if (withComments) { st->print("%s", _doc); } #endif st->cr(); } else if (!is_bool() && !is_ccstr()) { if (printRanges) { st->print("%9s %-50s ", _type, _name); CommandLineFlagRangeList::print(_name, st, true); st->print(" %-20s", " "); print_kind(st); #ifndef PRODUCT if (withComments) { st->print("%s", _doc); } #endif st->cr(); } } }
// read in the parallel rng state int read_par_rng_state( const char *infile ) { FILE *in = fopen( infile , "rb" ) ; struct QCDheader *get_header( FILE *__restrict in ) , * hdr ; char *str ; if( in == NULL ) { fprintf( stderr , "[PAR_RNG] State file %s not found\n" , infile ) ; return GLU_FAILURE ; } if( ( hdr = get_header( in ) ) == NULL ) { fprintf( stderr , "[PAR_RNG] Unable to read state header\n" ) ; return GLU_FAILURE ; } // check Nthreads size_t Nthreads ; if( get_size_t( "NTHREADS" , hdr , &Nthreads ) == GLU_FAILURE ) { fprintf( stderr , "[PAR_RNG] NTHREADS not found in header\n" ) ; return GLU_FAILURE ; } if( Nthreads != (size_t)Latt.Nthreads ) { fprintf( stderr , "[PAR_RNG] RNG Nthreads not the same as Latt.Nthreads\n" ) ; return GLU_FAILURE ; } // figure out what RNG we are using and make sure it is consistent if( get_string( "RNG" , hdr , &str ) == GLU_FAILURE ) { fprintf( stderr , "[PAR_RNG] RNG type not found" ) ; return GLU_FAILURE ; } #if (defined KISS_RNG) if( strcmp( " PAR_KISS" , str ) ) { fprintf( stderr , "[PAR_RNG] state RNG differs from compiled (KISS) RNG\n" ) ; return GLU_FAILURE ; } if( read_par_KISS_table( in ) == GLU_FAILURE ) { return GLU_FAILURE ; } #elif (defined MWC_4096_RNG) if( strcmp( " PAR_MWC_4096" , str ) ) { fprintf( stderr , "[PAR_RNG] state RNG differs from compiled (MWC_4096) RNG\n" ) ; return GLU_FAILURE ; } if( read_par_MWC_4096_table( in ) == GLU_FAILURE ) { return GLU_FAILURE ; } #elif (defined XOR_1024_RNG) if( strcmp( " PAR_XOR_1024" , str ) ) { fprintf( stderr , "[PAR_RNG] state RNG differs from compiled (XOR_1024) RNG\n" ) ; return GLU_FAILURE ; } if( read_par_XOR_1024_table( in ) == GLU_FAILURE ) { return GLU_FAILURE ; } #elif (defined MWC_1038_RNG) if( strcmp( " PAR_MWC_1038" , str ) ) { fprintf( stderr , "[PAR_RNG] state RNG differs from compiled (MWC_1038) RNG\n" ) ; return GLU_FAILURE ; } if( read_par_MWC_1038_table( in ) == GLU_FAILURE ) { return GLU_FAILURE ; } #else if( strcmp( " PAR_WELL_512" , str ) ) { fprintf( stderr , "[PAR_RNG] state RNG differs from compiled (WELL_512) RNG\n" ) ; return GLU_FAILURE ; } if( read_par_WELL_512_table( in ) == GLU_FAILURE ) { return GLU_FAILURE ; } #endif fclose( in ) ; return GLU_SUCCESS ; }