Example #1
0
void InitializeEmbeddedDescriptor(DescriptorClass *desc, StatementClass *stmt,
		 UInt4 desc_type) 
{
	DC_Constructor(desc, TRUE, stmt);
	DC_get_conn(desc) = SC_get_conn(stmt);
	desc->type_defined = TRUE;
	desc->desc_type = desc_type;
	switch (desc_type)
	{
		case SQL_ATTR_APP_ROW_DESC:
			memset(desc + 1, 0, sizeof(ARDFields));
			stmt->ard = (ARDClass *) desc;
			break; 
		case SQL_ATTR_APP_PARAM_DESC:
			memset(desc + 1, 0, sizeof(APDFields));
			stmt->apd = (APDClass *) desc;
			break; 
		case SQL_ATTR_IMP_ROW_DESC:
			memset(desc + 1, 0, sizeof(IRDFields));
			stmt->ird = (IRDClass *) desc;
			stmt->ird->irdopts.stmt = stmt;
			break; 
		case SQL_ATTR_IMP_PARAM_DESC:
			memset(desc + 1, 0, sizeof(IPDFields));
			stmt->ipd = (IPDClass *) desc;
			break; 
	}
}
Example #2
0
//通过锁记录id查锁信息,通过这个查询的本来就不需要name,name都一样,直接用传输协议的参数
OLInfo *getOLInfoByID(uint16 userlock_id,uint64 starttime,uint8 num)
{
//	debug("in get ol info byid\n");
	if((userlock_id == (uint16)0) || (starttime == (uint64)0) || (num == (uint8)0))
		return NULL;
	MYSQL *conn = getIdleConn();
	MYSQL_RES *res;      //查询的result
	MYSQL_ROW row;
	char *sql_str = NULL;   //sql语句
	
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"select open_time,close_time from OpenLockInfo where open_time > %llu and userlock_id = %2u order by open_time limit %1u",starttime,userlock_id,num);
	//执行查询
	if(mysql_query(conn,sql_str))
	{
		debug("getOLInfoByID error\n");
		recycleConn(conn);
		free(sql_str);
		return NULL;
	}
	//获取查询结果
	res = mysql_use_result(conn);
	OLInfo *info = NULL, *preInfo = NULL,*curInfo = NULL;
	//如果查询结果不为空
//	debug("middle get ol info by id\n");
	if((row = mysql_fetch_row(res)) != NULL)
	{
		curInfo = (OLInfo *)malloc(sizeof(OLInfo));
		memset(curInfo,0,sizeof(OLInfo));
		curInfo->open_time = (uint64)atoll(row[0]);
		if(row[1] == NULL)
			curInfo->close_time = 0;
		else
			curInfo->close_time = (uint64)atoll(row[1]);
		info = curInfo;
		preInfo = curInfo;
		while((row = mysql_fetch_row(res)) != NULL)
		{
			curInfo = (OLInfo *)malloc(sizeof(OLInfo));
			memset(curInfo,0,sizeof(OLInfo));
			curInfo->open_time = (uint64)atoll(row[0]);
			if(row[1] == NULL)
				curInfo->close_time = 0;
			else
				curInfo->close_time = (uint64)atoll(row[1]);
			preInfo->next = curInfo;
			preInfo = preInfo->next;
		}
	}
//	debug("after getolinfobyid \n");
	//释放资源
	mysql_free_result(res);
	recycleConn(conn);
	free(sql_str);
	return info;
}
Example #3
0
/*
 * Get a captured packet.
 */
size_t get_packet(uint8_t *buff, size_t size)
{
    if (size <= sizeof(struct ethhdr))
    {
        return 0;
    }

    ssize_t result;
    do
    {
        result = recv(socket_divert, buff + sizeof(struct ethhdr),
            size - sizeof(struct ethhdr), 0);
        if (result < 0)
        {
            warning("failed to read packet from netfilter socket");
            continue;
        }
    }
    while (false);

    // Add fake ethhdr
    struct ethhdr *eth_header = (struct ethhdr *)buff;
    memset(&eth_header->h_dest, 0x0, ETH_ALEN);
    memset(&eth_header->h_source, 0x0, ETH_ALEN);
    eth_header->h_proto = htons(ETH_P_IP);

    return (size_t)result + sizeof(struct ethhdr);
}
Example #4
0
/****************************************************************************
 *
 *  NAME        : SpiA2D_Init
 *
 *  DESCRIPTION : Initialization of the modoule
 *
 ****************************************************************************/
void SpiA2D_Init (void)
{

// zero the Rx Buffers:
	memset(A2DRxBuffer,0,A2D_BUFFERS_NUM * A2D_GET_VALUES_INST_LENGTH);
	memset(A2DRxBufferSW_Version, 0, A2D_GET_SW_VERSION_INST_LENGTH); 

// the pointer to the samples buffer points to the second byte of the 
// Rx buffer (the first byte is junk received after sending the command)
	A2DSamplesBuffer = (WORD*)(A2DRxBuffer[0] + 1);

// the SW Version buffer (= A2DRxBufferSW_Version) without the first byte
	A2D_SW_VersionBuffer = (WORD*)(A2DRxBufferSW_Version[0] + 1);

	RxBufferNum = 0;

    TaskCycles = 0;

// Route vref to a port pin (for use of the A2D CPU)
  REF0CN |= 0x01;
  
  DataIsValid = FALSE;

  // A2D SW Ver. is updated only once - here:
  // SpiA2D_GetSwVersionBySpi();    
}
int main()
{
  char buf[BSZ];

  memset(buf, 'a', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  FILE *fp = fmemopen(buf, BSZ, "w+");
  if (fp == NULL)
    err_exit("fmemopen failed");
  printf("initial buffer contents: %s\n", buf);
  fprintf(fp, "hello, world");
  printf("before flush: %s\n", buf);
  fflush(fp);
  printf("after fflush: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  memset(buf, 'b', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  fprintf(fp, "hello, world");
  fseek(fp, 0, SEEK_SET);
  printf("after  fseek: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  memset(buf, 'c', BSZ-2);
  buf[BSZ-2] = '\0';
  buf[BSZ-1] = 'X';
  fprintf(fp, "hello, world");
  fclose(fp);
  printf("after fclose: %s\n", buf);
  printf("len of string in buf = %ld\n", (long)strlen(buf));

  return(0);
}
void out_redirect(char input[]){
                int fd;
                char *tok;
		char path[256];
		char command[256];

		memset(path,0,256);
		memset(command,0,256);


                tok=strtok(input,">");
	        strcpy(command,tok);
		
                tok = strtok(NULL," ");
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
                
   

                fd = open(path,O_WRONLY|O_CREAT);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);
		

}
Example #7
0
void sys_setchsr(int chin, int chout, int sr)
{
    int inbytes = (chin ? chin : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample));
    int outbytes = (chout ? chout : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample));

    if (STUFF->st_soundin)
        freebytes(STUFF->st_soundin,
            (STUFF->st_inchannels? STUFF->st_inchannels : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample)));
    if (STUFF->st_soundout)
        freebytes(STUFF->st_soundout,
            (STUFF->st_outchannels? STUFF->st_outchannels : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample)));
    STUFF->st_inchannels = chin;
    STUFF->st_outchannels = chout;
    STUFF->st_dacsr = sr;
    sys_advance_samples = (sys_schedadvance * STUFF->st_dacsr) / (1000000.);
    if (sys_advance_samples < DEFDACBLKSIZE)
        sys_advance_samples = DEFDACBLKSIZE;

    STUFF->st_soundin = (t_sample *)getbytes(inbytes);
    memset(STUFF->st_soundin, 0, inbytes);

    STUFF->st_soundout = (t_sample *)getbytes(outbytes);
    memset(STUFF->st_soundout, 0, outbytes);

    if (sys_verbose)
        post("input channels = %d, output channels = %d",
            STUFF->st_inchannels, STUFF->st_outchannels);
    canvas_resume_dsp(canvas_suspend_dsp());
}
Example #8
0
struct audiosource* audiosourcefile_Create(const char* path) {
    struct audiosource* a = malloc(sizeof(*a));
    if (!a) {
        return NULL;
    }

    memset(a,0,sizeof(*a));
    a->internaldata = malloc(sizeof(struct audiosourcefile_internaldata));
    if (!a->internaldata) {
        free(a);
        return NULL;
    }

    struct audiosourcefile_internaldata* idata = a->internaldata;
    memset(idata, 0, sizeof(*idata));
    idata->path = strdup(path);
    if (!idata->path) {
        free(a->internaldata);
        free(a);
        return NULL;
    }

    a->read = &audiosourcefile_Read;
    a->close = &audiosourcefile_Close;
    a->rewind = &audiosourcefile_Rewind;
    a->seek = &audiosourcefile_Seek;
    a->length = &audiosourcefile_Length;
    a->position = &audiosourcefile_Position;
    a->seekable = 1;

    return a;
}
Example #9
0
void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b){
	uint8_t buffer[SHA256_HASH_BYTES];
	uint8_t i;
	sha256_ctx_t a;
	
	memset(buffer, 0, SHA256_HASH_BYTES);
	if (keylength_b > SHA256_BLOCK_BITS){
		sha256((void*)buffer, key, keylength_b);
	} else {
		memcpy(buffer, key, (keylength_b+7)/8);
	}
	
	for (i=0; i<SHA256_HASH_BYTES; ++i){
		buffer[i] ^= OPAD;
	}
	
	sha256_init(&a);
	sha256_nextBlock(&a, buffer); /* hash key ^ opad */
	sha256_ctx2hash((void*)buffer, s);  /* copy hash(key ^ ipad, msg) to buffer */
	sha256_lastBlock(&a, buffer, SHA256_HASH_BITS);
	memcpy(s, &a, sizeof(sha256_ctx_t));
#if defined SECURE_WIPE_BUFFER
	memset(buffer, 0, SHA256_HASH_BYTES);
	memset(a.h, 0, 8*4);
#endif	
}
Example #10
0
/*
* CL_MouseFilterBufferSizeSet_f
*/
static dynvar_set_status_t CL_MouseFilterBufferSizeSet_f( void *size )
{
	static const unsigned int MIN_SIZE = 1;
	static const unsigned int MAX_SIZE = 32; // more is pointless (probably anything more than 5)
	const unsigned int desiredSize = atoi( (char *) size );
	if( desiredSize >= MIN_SIZE && desiredSize <= MAX_SIZE )
	{
		// reallocate buffer
		if( m_filter->integer != M_FILTER_EXTRAPOLATE )
			Com_Printf( "Warning: \"m_filterBufferSize\" has no effect unless \"m_filter " M_DOUBLEQUOTE( M_FILTER_EXTRAPOLATE ) "\" is set.\n" );
		Mem_ZoneFree( buf_x );
		Mem_ZoneFree( buf_y );
		buf_x = (float *) Mem_ZoneMalloc( sizeof( float ) * desiredSize );
		buf_y = (float *) Mem_ZoneMalloc( sizeof( float ) * desiredSize );
		// reset to 0
		memset( buf_x, 0, sizeof( float ) * desiredSize );
		memset( buf_y, 0, sizeof( float ) * desiredSize );
		buf_size = desiredSize;
		return DYNVAR_SET_OK;
	}
	else
	{
		Com_Printf( "\"m_filterBufferSize\" must be between \"%d\" and \"%d\".\n", MIN_SIZE, MAX_SIZE );
		return DYNVAR_SET_INVALID;
	}
}
Example #11
0
int main( int argc, char *argv[] )
{
    char x[300];
    char *ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "memset() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "      ");
    ret = memset(x, 'X', 5);
    if ((my_strcmp(x, "XXXXX ") == 0) && (ret == x))
        CYG_TEST_PASS("Simple memset");
    else
        CYG_TEST_FAIL("Simple memset");

    // Check 2
    my_strcpy(x, "XXXXX ");
    ret = memset(x, 'Y', 0);
    if ((my_strcmp(x, "XXXXX ") == 0) && (ret == x))
        CYG_TEST_PASS("Boundary case of 0 bytes");
    else
        CYG_TEST_FAIL("Boundary case of 0 bytes");

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "memset() function");

} // main()
Example #12
0
psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
{    
    char *node = NULL;
    char  model_name[I2C_PSU_MODEL_NAME_LEN + 1] = {0};   

    /* Check model name */
    node = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_mfr_model) : PSU2_AC_PMBUS_NODE(psu_mfr_model);
    memset(model_name, 0x0, I2C_PSU_MODEL_NAME_LEN + 1);
    memset(modelname, 0x0, modelname_len); 
    if (onlp_file_read_string(node, model_name, sizeof(model_name), 0) != 0) {
        
        return PSU_TYPE_UNKNOWN;
    }
	
	if (!strncmp(model_name, "FSH082", strlen("FSH082")))
	{
	    if (modelname)
            strncpy(modelname, model_name, strlen("FSH082")<(modelname_len-1)?strlen("FSH082"):(modelname_len-1));
        
        return PSU_TYPE_ACBEL;
    }
    if (!strncmp(model_name, "YM-2651Y", strlen("YM-2651Y")))
    {
        if (modelname)
            strncpy(modelname, model_name, modelname_len-1);   
        return PSU_TYPE_YM2651Y;
    }

    return PSU_TYPE_UNKNOWN;
}
Example #13
0
WMORoot::WMORoot(std::string &filename)
    : filename(filename), col(0), nTextures(0), nGroups(0), nP(0), nLights(0),
    nModels(0), nDoodads(0), nDoodadSets(0), RootWMOID(0), liquidType(0)
{
    memset(bbcorn1, 0, sizeof(bbcorn1));
    memset(bbcorn2, 0, sizeof(bbcorn2));
}
OverlappedIOContext::OverlappedIOContext(ClientSession* owner, IOType ioType) 
: mSessionObject(owner), mIoType(ioType)
{
	memset(&mOverlapped, 0, sizeof(OVERLAPPED));
	memset(&mWsaBuf, 0, sizeof(WSABUF));
	mSessionObject->AddRef();
}
Example #15
0
void Triangles::clear() {
    for (int i = 0; i < triangleCount; i++) {
        /*if (triangles[i].textureName != 0)
            delete triangles[i].textureName;*/
        if (triangles[i].isUsed)
            renderManager->removeTriangle(triangles[i].index);
    }
    free(triangles);

    for (int i = 0; i < vertexCount; i++) {
        if (vertices[i].isUsed)
            renderManager->removeTriangleVertex(vertices[i].index);
    }
    free(vertices);

    textureNames.clear();

    vertexCount = 0;
    vertexCapacity = 16;
    vertices = (Vertex*)malloc(vertexCapacity * sizeof(Vertex));
    memset(vertices, 0, vertexCapacity * sizeof(Vertex));

    triangleCount = 0;
    triangleCapacity = 16;
    triangles = (Triangle*)malloc(triangleCapacity * sizeof(Triangles));
    memset(triangles, 0, triangleCapacity * sizeof(Triangle));
}
Example #16
0
/* 
 * multi-session authcode generation for MD2
 * H(password + session_id + msg + session_seq + password)
 *
 * Use OpenSSL implementation of MD2 algorithm if found.
 * This function is analogous to ipmi_auth_md5
 */
uint8_t * ipmi_auth_md2(struct ipmi_session * s, uint8_t * data, int data_len)
{
#ifdef HAVE_CRYPTO_MD2
	MD2_CTX ctx;
	static uint8_t md[16];
	uint32_t temp;

#if WORDS_BIGENDIAN
	temp = BSWAP_32(s->in_seq);
#else
	temp = s->in_seq;
#endif
	memset(md, 0, 16);
	memset(&ctx, 0, sizeof(MD2_CTX));

	MD2_Init(&ctx);
	MD2_Update(&ctx, (const uint8_t *)s->authcode, 16);
	MD2_Update(&ctx, (const uint8_t *)&s->session_id, 4);
	MD2_Update(&ctx, (const uint8_t *)data, data_len);
	MD2_Update(&ctx, (const uint8_t *)&temp, sizeof(uint32_t));
	MD2_Update(&ctx, (const uint8_t *)s->authcode, 16);
	MD2_Final(md, &ctx);

	//if (verbose > 3)
	//	printf("  MD2 AuthCode    : %s\n", buf2str(md, 16));

	return md;
#else /*HAVE_CRYPTO_MD2*/
	static uint8_t md[16];
	memset(md, 0, 16);
	printf("WARNING: No internal support for MD2!  "
	       "Please re-compile with OpenSSL.\n");
	return md;
#endif /*HAVE_CRYPTO_MD2*/
}
void append_redirect(char input[]){
		//printf("!1\n");
                int fd;
                char *tok;
                char path[256];
                char command[256];

                memset(path,0,256);
                memset(command,0,256);


                tok=strtok(input,">");
		//printf("!2%s\n",tok);
                strcpy(command,tok);
		
                tok = strtok(NULL,">");
		//printf("!3%s\n",tok);
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
		//printf("!4%s\n",path);
                fd = open(path,O_RDWR|O_CREAT|O_APPEND);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);

          


}
Example #18
0
extern "C" int Java_com_dttv_dtlive_utils_LiveJniLib_native_1stream_1send(JNIEnv *env, jobject thiz, jbyteArray data, jint length) {

    jbyte* inbuf = env->GetByteArrayElements(data, NULL);
    LOGI("BEFORE SEND");
    for(int i = 0; i < 100; i += 5) {
        LOGI("%02x %02x %02x %02x %02x \n", inbuf[i], inbuf[i+1], inbuf[i+2], inbuf[i+3], inbuf[i+4]);
    }
    LOGI("AFTER SEND");
    int size = 0;
    if(rtmp_handle && flvmux_handle) {

        struct flvmux_packet in, out;
        memset(&in, 0, sizeof(struct flvmux_packet));
        memset(&out, 0, sizeof(struct flvmux_packet));
        in.data = (uint8_t *)inbuf;
        in.size = length;

        size = flvmux_setup_video_frame(flvmux_handle, &in, &out);
        if(size < 0) {
            LOGI("flv setup video frame failed \n");
            return 0;
        }
        size = rtmp_write(rtmp_handle, out.data, size);
        if(size < 0) {
            LOGI("rtmp send frame failed:%d", size);
        }
        free(out.data);

        LOGI("rtmp send frame ok:%d", size);
    }
    return 0;
}
void bad()
{
    char * data;
    data = NULL;
    if(staticFive==5)
    {
        {
            char * dataBuffer = new char[100];
            memset(dataBuffer, 'A', 100-1);
            dataBuffer[100-1] = '\0';
            /* FLAW: Set data pointer to before the allocated memory buffer */
            data = dataBuffer - 8;
        }
    }
    {
        size_t i;
        char source[100];
        memset(source, 'C', 100-1); /* fill with 'C's */
        source[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
        for (i = 0; i < 100; i++)
        {
            data[i] = source[i];
        }
        /* Ensure the destination buffer is null terminated */
        data[100-1] = '\0';
        printLine(data);
        /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
         * returned by new [] so can't safely call delete [] on it */
    }
}
Example #20
0
static void
event_callback(snl_socket_t *skt) {
   char *data, cmd[32], arg[32], ret[STRING_SIZE];
   int err = UNKNOWN_COMMAND;

   if (skt->event_code == SNL_EVENT_RECEIVE) {
      data = (char *)skt->data_buffer;
      data[skt->data_length] = '\0';

      // remove last command from buffers
      memset(cmd, 0, 32);
      memset(arg, 0, 32);

      memset(ret, 0, STRING_SIZE);

      sscanf(data, "%31s %31s", cmd, arg);

      syslog(LOG_DEBUG, "received: %s %s", cmd, arg);

      if (cmd[0] == 'C') err = ExecGenericCommand(ret, cmd);
      else if (!strcmp(cmd,  "power")) err = ExecPowerCommand(ret, arg);
      else if (!strcmp(cmd,  "input")) err = ExecInputCommand(ret, arg);
      else if (!strcmp(cmd, "scaler")) err = ExecScalerCommand(ret, arg);
      else if (!strcmp(cmd,   "lamp")) err = ExecLampCommand(ret, arg);
      else if (!strcmp(cmd,  "color")) err = ExecColorCommand(ret, arg);
      else if (!strcmp(cmd,   "menu")) err = ExecMenuCommand(ret, arg);
      else if (!strcmp(cmd,   "mute")) err = ExecMuteCommand(ret, arg);
      else if (!strcmp(cmd,  "press")) err = ExecPressCommand(ret, arg);
      else if (!strcmp(cmd,   "logo")) err = ExecLogoCommand(ret, arg);
      else if (!strcmp(cmd, "status")) err = ExecStatusRead(ret, arg);
      else if (!strcmp(cmd,  "model")) err = ReadModelNumber(ret);
      else if (!strcmp(cmd,  "onkyo")) err = OnkyoExecCommand(ret, arg);

      switch (err) {
         case UNKNOWN_COMMAND:
            syslog(LOG_ERR, "unknown command");
         break;

         case INVALID_ARGUMENT:
            syslog(LOG_ERR, "invalid argument");
         break;

         case WRITE_ERROR:
            syslog(LOG_ERR, "serial write error");
         break;

         case READ_TIMEOUT:
            syslog(LOG_ERR, "serial read timeout");
         break;

         case OPEN_FAILED:
            syslog(LOG_ERR, "serial device open failed");
         break;

         default:
            syslog(LOG_DEBUG, "response: %s", ret);
         break;
      }
   }
}
Example #21
0
/**@brief Function for initializing the Services generated by Bluetooth Developer Studio.
 *
 *
 * @return      NRF_SUCCESS on successful initialization of services, otherwise an error code.
 */
uint32_t bluetooth_init(void)
{
    uint32_t    err_code; 
    ble_gpio_test_service_init_t    gpio_test_service_init; 
    

    // Initialize GPIO Test Service.
    memset(&gpio_test_service_init, 0, sizeof(gpio_test_service_init));

    gpio_test_service_init.evt_handler = on_gpio_test_service_evt; 
    memset(&gpio_test_service_init.ble_gpio_test_service_led_initial_value.toggle_led,
           0x00,
           sizeof(gpio_test_service_init.ble_gpio_test_service_led_initial_value.toggle_led));
    memset(&gpio_test_service_init.ble_gpio_test_service_button_initial_value.button_state,
           0x00,
           sizeof(gpio_test_service_init.ble_gpio_test_service_button_initial_value.button_state));

    err_code = ble_gpio_test_service_init(&m_gpio_test_service, &gpio_test_service_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    } 

    return NRF_SUCCESS;
}
Example #22
0
int main(void)
{
	int sock;
	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
		ERR_EXIT("socket");
	struct sockaddr_in servaddr;
	memset(&servaddr, 0 ,sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(5188);
	servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
	
	if(connect(sock, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0)
		ERR_EXIT("connect");
	printf("connect.....\n");
	char sendbuf[1024] = {0};
	char recvbuf[1024] = {0};
	while(fgets(sendbuf, sizeof(sendbuf), stdin) != NULL)
	{
		write(sock, sendbuf, strlen(sendbuf));
		read(sock, recvbuf, sizeof(recvbuf));

		fputs(recvbuf, stdout);
		memset(sendbuf, 0, sizeof(sendbuf));
		memset(recvbuf, 0, sizeof(recvbuf));
	}
	close(sock);
	return 0;
}
Example #23
0
unsigned char *EncryptXXTea::decode()
{
    UserData user_d = {10,20,30};
    unsigned char *t_data = (unsigned char *)&user_d;
    const  char *key_s = "YuanfeiTestXXTea";
    xxtea_long key_len = strlen(key_s);
    xxtea_long ret_len;
    unsigned char *bufs=xxtea_encrypt(t_data, sizeof(UserData), (unsigned char*)key_s, key_len, &ret_len);
    
    char t_buf[512];
    memset(&t_buf, 0, 512);
    memcpy(&t_buf, bufs, ret_len+1);
    
    key_s = "YuanfeiTestXXTea";
    key_len = strlen(key_s);
    xxtea_long de_len;
    unsigned char *de_data=xxtea_decrypt(bufs, ret_len, (unsigned char*)key_s, key_len, &de_len);
    memset(&t_buf, 0, 512);
    memcpy(&t_buf, de_data, ret_len+1);
    
    UserData decod;
    memset(&decod, 0, sizeof(UserData));
    memcpy(&decod, de_data, sizeof(UserData));
    return nullptr;

}
/* goodG2B2() - use goodsource and badsink by reversing the blocks in the if statement */
static void goodG2B2()
{
    char * data;
    data = NULL;
    if(GLOBAL_CONST_TRUE)
    {
        {
            char * dataBuffer = new char[100];
            memset(dataBuffer, 'A', 100-1);
            dataBuffer[100-1] = '\0';
            /* FIX: Set data pointer to the allocated memory buffer */
            data = dataBuffer;
        }
    }
    {
        char source[100];
        memset(source, 'C', 100-1); /* fill with 'C's */
        source[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
        memcpy(data, source, 100*sizeof(char));
        /* Ensure the destination buffer is null terminated */
        data[100-1] = '\0';
        printLine(data);
        /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
         * returned by new [] so can't safely call delete [] on it */
    }
}
/////////////////////////////////////////////////////
//
// The compact hash table writer implementations
//
CompactHashtableWriter::CompactHashtableWriter(int table_type,
                                               int num_entries,
                                               CompactHashtableStats* stats) {
  assert(DumpSharedSpaces, "dump-time only");
  _type = table_type;
  _num_entries = num_entries;
  _num_buckets = number_of_buckets(_num_entries);
  _buckets = NEW_C_HEAP_ARRAY(Entry*, _num_buckets, mtSymbol);
  memset(_buckets, 0, sizeof(Entry*) * _num_buckets);

  /* bucket sizes table */
  _bucket_sizes = NEW_C_HEAP_ARRAY(juint, _num_buckets, mtSymbol);
  memset(_bucket_sizes, 0, sizeof(juint) * _num_buckets);

  stats->hashentry_count = _num_entries;
  // Compact buckets' entries will have only the 4-byte offset, but
  // we don't know how many there will be at this point. So use a
  // conservative estimate here. The size is adjusted later when we
  // write out the buckets.
  stats->hashentry_bytes = _num_entries * 8;
  stats->bucket_count    = _num_buckets;
  stats->bucket_bytes    = (_num_buckets + 1) * (sizeof(juint));
  _stats = stats;

  // See compactHashtable.hpp for table layout
  _required_bytes = sizeof(juint) * 2; // _base_address, written as 2 juints
  _required_bytes+= sizeof(juint) +    // num_entries
                    sizeof(juint) +    // num_buckets
                    stats->hashentry_bytes +
                    stats->bucket_bytes;
}
Example #26
0
/* Sends a ping packet out the radio */
static void
raven_ping6(uip_ipaddr_t *addr, int len)
{

    UIP_IP_BUF->vtc = 0x60;
    UIP_IP_BUF->tcflow = 0;
    UIP_IP_BUF->flow = 0;
    UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
    UIP_IP_BUF->ttl = UIP_TTL;
    uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, addr);
    uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);

    UIP_ICMP_BUF->type = ICMP6_ECHO_REQUEST;
    UIP_ICMP_BUF->icode = 0;
    /* set identifier and sequence number to 0 */
    memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, UIP_ICMP6_ECHO_REQUEST_LEN);
    /* put len bytes of all one data */
    memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN,
           1, len);

    uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + len;
    UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
    UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF);

    UIP_ICMP_BUF->icmpchksum = 0;
    UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();

    tcpip_ipv6_output();
}
Example #27
0
void ThumbnailProvider::shrink4x4SSE(const ImageBH& srcImage, ThumbnailBH::ThumbnailImage& destImage)
{
  int scaleFactor = 4;
  int averagedPixels = scaleFactor * scaleFactor;
  ASSERT(srcImage.width % scaleFactor == 0);
  ASSERT(srcImage.height % scaleFactor == 0);

  destImage.setResolution(srcImage.width / scaleFactor, srcImage.height / scaleFactor);
  int height = srcImage.height;
  int width = srcImage.width;

  static const __m128i zero = _mm_setzero_si128();
  __m128i* summs = reinterpret_cast<__m128i*>(SystemCall::alignedMalloc(16 * destImage.width, 16));
  memset(summs, 0, destImage.width * 16);

  const ImageBH::Pixel* pSrc;
  ThumbnailBH::ThumbnailImage::PixelType* pDest;
  __m128i* pSumms;

  __m128i tmp;
  __m128i lower;
  __m128i upper;

  for(int y = 0; y < height; ++y)
  {
    if(y % scaleFactor == 0)
    {
      pDest = destImage[y / scaleFactor];
    }
    pSrc = srcImage[y];
    pSumms = summs;
    for(int x = 0; x < width; x += scaleFactor, pSrc += scaleFactor, ++pSumms)
    {
      tmp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(pSrc));
      lower = _mm_unpacklo_epi8(tmp, zero);
      upper = _mm_unpackhi_epi8(tmp, zero);
      *pSumms = _mm_add_epi16(*pSumms, lower);
      *pSumms = _mm_add_epi16(*pSumms, upper);
    }

    if(y % scaleFactor == scaleFactor - 1)
    {
      pSumms = summs;
      for(int i = 0; i < destImage.width; ++i, ++pSumms, ++pDest)
      {
        short* ptr = reinterpret_cast<short*>(pSumms);

        short sumY = ptr[offsetof(ImageBH::Pixel, y)] + ptr[offsetof(ImageBH::Pixel, y) + sizeof(ImageBH::Pixel)];
        short sumCb = ptr[offsetof(ImageBH::Pixel, cb)] + ptr[offsetof(ImageBH::Pixel, cb) + sizeof(ImageBH::Pixel)];
        short sumCr = ptr[offsetof(ImageBH::Pixel, cr)] + ptr[offsetof(ImageBH::Pixel, cr) + sizeof(ImageBH::Pixel)];

        pDest->y = static_cast<char>(sumY / averagedPixels);
        pDest->cb = static_cast<char>(sumCb / averagedPixels);
        pDest->cr = static_cast<char>(sumCr / averagedPixels);
      }
      memset(summs, 0, destImage.width * 16);
    }
  }
  SystemCall::alignedFree(summs);
}
Example #28
0
static int GetSysParam(const char *para,char *value)
{
    int ret;
    ST_CPACK aPack,sPack;
    memset(&sPack,0,sizeof sPack);
    memset(&aPack,0,sizeof aPack);

    ResetNormalCPack(&sPack,0,1);
    SetHeadCol(&sPack,F_SNAME,F_SNAME2,0);
    sPack.head.RequestType = 850007;
    strcpy(sPack.pack.sname,"GDCT");
    strcpy(sPack.pack.sname2,para);
    ret = ExtCall(0,g_mainsvr_drtpno,g_mainsvr_func,0,3,&sPack,&aPack,NULL);
    if(ret>=0)
    {
        if(aPack.head.retCode!=0)
            return aPack.head.retCode;
        strncpy(value,aPack.pack.vsvarstr0,128);
        return 0;
    }
    else
    {
        return -1;
    }
}
void InputDevice_DualShock::Power(void)
{
 combo_anatoggle_counter = -2;
 lastts = 0;
 //
 //

 dtr = 0;

 buttons[0] = buttons[1] = 0;

 command_phase = 0;

 bitpos = 0;

 receive_buffer = 0;

 command = 0;

 memset(transmit_buffer, 0, sizeof(transmit_buffer));

 transmit_pos = 0;
 transmit_count = 0;

 analog_mode_locked = false;

 mad_munchkins = false;
 memset(rumble_magic, 0xFF, sizeof(rumble_magic));
 memset(rumble_param, 0, sizeof(rumble_param));

 da_rumble_compat = true;

 prev_ana_button_state = false;
}
Example #30
0
void ResetTracks( TRACKS* pTracks )
{
	int i;
	pTracks->main_video_index = 0xffff;
	pTracks->main_audio_index = 0xffff;
	pTracks->track_attr = 0;
	pTracks->number_track = 0;
	for ( i = 0; i <pTracks->total_track; i++ )
	{
		pTracks->track[i].channel_index = i;
		pTracks->track[i].buffer_index = 0;
		pTracks->track[i].buffer_size = 0;
		pTracks->track[i].buffer_start = NULL;
		pTracks->track[i].cue = 0;
		pTracks->track[i].start_cue = 0;
		pTracks->track[i].es_data_bytes = 0;
		pTracks->track[i].ts_packets_counter = 0;
		pTracks->track[i].es_blocks_counter = 0;
		pTracks->track[i].processed_bytes = 0;
		pTracks->track[i].scrambling_flag = 0;
		if ( pTracks->track[i].ts_elmnt )
			memset( pTracks->track[i].ts_elmnt, 0, sizeof(TS_ELEMENT) );
		if ( pTracks->track[i].es_elmnt )
			memset( pTracks->track[i].es_elmnt, 0, sizeof(ES_ELEMENT) );
		if ( pTracks->track[i].av_elmnt )
			memset( pTracks->track[i].av_elmnt, 0, sizeof(AV_ELEMENT) );
	}
}