But I am just handling arrived data when *upload_data_size > 0. Here is the
code:
else if(strcmp(method, "POST") == 0)
{
ST_PER_THREAD_DATA* pstThreadData = *ptr;
if( pstThreadData == NULL)
{
ST_PER_THREAD_DATA * cThreadData = (ST_PER_THREAD_DATA*)
malloc(sizeof(ST_PER_THREAD_DATA));
cThreadData->nThreadID = nThID;
cThreadData->strData[0]='\0';
*ptr = cThreadData;
return MHD_YES;
}
if(*upload_data_size > 0)
{
printf("Before strcpy (%s) (%s)
(%d)\n",pstThreadData->strData,upload_data,*upload_data_size);
strncpy(pstThreadData->strData,upload_data,*upload_data_size);
printf("After strcpy (%s) (%s)
(%d)\n",pstThreadData->strData,upload_data,*upload_data_size);
*upload_data_size = 0;
return MHD_YES;
//After strcpy ({"key98"}) ({"key98"}) (9)
}
else
{
//END OF POST DATA GATHERING
printf("In the end of post we have (%s) (%d)
\n",pstThreadData->strData, strlen(pstThreadData->strData));
HandleClientPost(pstThreadData->strData))
//In the end of post we have ({"key98"}) (10)
...
Please, is there anything wrong with the (testing) code?
Thank you
On Mon, Apr 13, 2020 at 10:00 AM Christian Grothoff <[email protected]>
wrote:
> On 4/13/20 2:11 AM, Imóveis Nacionais wrote:
> > Then when in the "*upload_data_size = 0" situation, using a printf
> > sometimes I can see that the thread context data has the 0x7f char
> appended
> > and of course the strlen now is one char extra. This happens between the
> > last post call with *upload_data_size > 0 and *upload_data_size = 0.
> >
> > Does this char has any meaning in the libmicrohttpd context?
> > Why is this char being added?
>
> You're seeing undefined behavior. When '*upload_data_size' is zero, you
> are not allowed to look into '*upload_data'. It is NEVER warranted to be
> a 0-terminated char* in the first place, and right now you're just
> reading data out of bounds. Do not rely on getting 0x7f or anything
> meaningful, in fact, expect reading more than '*upload_data_size' bytes
> from '*upload_data' to be deadly.
>
> Happy hacking!
>
> Christian
>
>