protection from illformed msg
This commit is contained in:
parent
7c3aa655d7
commit
c724900448
|
@ -87,33 +87,36 @@ namespace buzz_utility{
|
||||||
unMsgSize = *(uint16_t*)(pl + tot);
|
unMsgSize = *(uint16_t*)(pl + tot);
|
||||||
|
|
||||||
fprintf(stdout,"received Msg size : %i\n",(int) *(uint16_t*)(pl + tot));
|
fprintf(stdout,"received Msg size : %i\n",(int) *(uint16_t*)(pl + tot));
|
||||||
tot += sizeof(uint16_t);
|
/*Xbee seems to send a lots of unknown message check later, added to avoid it, safe anyways*/
|
||||||
code_message_inqueue_append(pl+tot,unMsgSize);
|
if(*(uint16_t*)(pl + tot) >= 4){
|
||||||
fprintf(stdout,"Msg 1 : %i , and Msg 2: %i\n",(int) *(uint16_t*)(pl+tot),(int) *(uint8_t*)(pl+tot+sizeof(uint16_t)));
|
tot += sizeof(uint16_t);
|
||||||
tot += unMsgSize;
|
code_message_inqueue_append(pl+tot,unMsgSize);
|
||||||
code_message_inqueue_process();
|
fprintf(stdout,"Msg 1 : %i , and Msg 2: %i\n",(int) *(uint16_t*)(pl+tot),(int) *(uint8_t*)(pl+tot+sizeof(uint16_t)));
|
||||||
unMsgSize=0;
|
tot += unMsgSize;
|
||||||
/*Check for Buzz messages only when the code is running*/
|
code_message_inqueue_process();
|
||||||
if(get_update_mode()==CODE_RUNNING){
|
unMsgSize=0;
|
||||||
uint8_t buzz_msg_pre=*(uint8_t*)(pl + tot);
|
/*Check for Buzz messages only when the code is running*/
|
||||||
tot+= sizeof(uint8_t);
|
if(get_update_mode()==CODE_RUNNING){
|
||||||
/*Obtain Buzz messages only when they are present*/
|
uint8_t buzz_msg_pre=*(uint8_t*)(pl + tot);
|
||||||
if(buzz_msg_pre){
|
tot+= sizeof(uint8_t);
|
||||||
do {
|
/*Obtain Buzz messages only when they are present*/
|
||||||
/* Get payload size */
|
if(buzz_msg_pre){
|
||||||
unMsgSize = *(uint16_t*)(pl + tot);
|
do {
|
||||||
tot += sizeof(uint16_t);
|
/* Get payload size */
|
||||||
/* Append message to the Buzz input message queue */
|
unMsgSize = *(uint16_t*)(pl + tot);
|
||||||
if(unMsgSize > 0 && unMsgSize <= size - tot ) {
|
tot += sizeof(uint16_t);
|
||||||
buzzinmsg_queue_append(VM,
|
/* Append message to the Buzz input message queue */
|
||||||
buzzmsg_payload_frombuffer(pl +tot, unMsgSize));
|
if(unMsgSize > 0 && unMsgSize <= size - tot ) {
|
||||||
tot += unMsgSize;
|
buzzinmsg_queue_append(VM,
|
||||||
}
|
buzzmsg_payload_frombuffer(pl +tot, unMsgSize));
|
||||||
}while(size - tot > sizeof(uint16_t) && unMsgSize > 0);
|
tot += unMsgSize;
|
||||||
|
}
|
||||||
|
}while(size - tot > sizeof(uint16_t) && unMsgSize > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* Process messages */
|
||||||
|
buzzvm_process_inmsgs(VM);
|
||||||
}
|
}
|
||||||
/* Process messages */
|
|
||||||
buzzvm_process_inmsgs(VM);
|
|
||||||
}
|
}
|
||||||
/***************************************************/
|
/***************************************************/
|
||||||
/*Obtains messages from buzz out message Queue*/
|
/*Obtains messages from buzz out message Queue*/
|
||||||
|
|
Loading…
Reference in New Issue