With the dynamic array sizes you cannot do simple tests to check the size of the incoming packets..basically you just have to trust that player is passing you a valid data packet. If you want to be double certain then you can test that it is at least the size of the base structure...

The len field in publish is actually ignored rather than being optional, The one in Request is also ignored, although it gets passed on for a long time first.


On 15/11/2007, Paul Osmialowski <newchief@king.net.pl> wrote:
Hi Toby,

I'm trying to rewrite some plugin driver so it could be compiled with CVS
version of libplayercore. As we know, currently Publish() method parameter
that denotes the size of published data packet is optional and has default
value 0, which means, the size of the data can be dynamic and is computed.
In my driver I'm also using Request() method to send
PLAYER_SIMULATION_REQ_GET_POSE2D request, which means I have to fill
fields in player_simulation_pose2d_req_t structure. One of them (called
'name') has dynamic size. Unfortunately, 'len' parameter of Request()
method isn't optional, so I guess I have to pass size of the
player_simulation_pose2d_req_t structure.
My code is:

#define STRNCPY(dest, src, n) do \
{ \
   strncpy(dest, src, n); \
   ((dest)[n-1]) = 0; \
} while (0)

     player_position2d_data_t posdata;
     Message * msg;
     player_simulation_pose2d_req_t posreq, * posreq_new;
     memset(&posdata, 0, sizeof posdata);
     memset(&posreq, 0, sizeof posreq);
     posreq.name_count = strlen(this->object) + 1;
     posreq.name = new char[posreq.name_count ];
     STRNCPY(posreq.name, this->object, posreq.name_count);
     msg = this->simulation_dev->Request(this->InQueue,
                                         (void *)(&posreq),
                                         sizeof posreq,
                                         NULL, true);
     delete []posreq.name;
     posreq.name = NULL;
     if (!msg)
       PLAYER_WARN("failed to acquire position data");
     } else
       if ((msg->GetDataSize()) !=
         PLAYER_WARN2("invalid acqired data size %d vs %d",
msg->GetDataSize(), sizeof(player_simulation_pose2d_
       } else
         posreq_new = (player_simulation_pose2d_req_t
         if (!posreq_new)
           PLAYER_WARN("no data acquired");
         } else
           posdata.pos.px = posreq_new->pose.px;
           posdata.pos.py = posreq_new->pose.py;
           posdata.pos.pa = posreq_new->pose.pa;
       delete msg;
     msg = NULL;

As a result I'm getting warning:
invalid acqired data size 35 vs 32

What went wrong?
This code worked before recent changes...


This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Playerstage-developers mailing list

This email is intended for the addressee only and may contain privileged and/or confidential information