On 2015/6/9 19:17, Cyril Hrubis wrote:
> Hi!
>> for (i = 0, p = buffer.data; i < buffer.data_length; i++, p++)
>> *p = getc(fp);
>> fclose(fp);
>>
>> + return_buffer = malloc(buffer.data_length);
>> + if (!return_buffer) {
>> + fprintf(stderr, "malloc failed for return_buffer\n");
>> + free(buffer.data);
>> + exit(1);
>> + }
>> +
>> rc = callrpc(server, program, version, 1, (xdrproc_t)xdr_send_data,
>> - (char *)&buffer, (xdrproc_t)xdr_receive_data,
>> - (char *)&return_buffer);
>> - do_compare(rc, "callrpc", &buffer, return_buffer->data);
>> + buffer.data, (xdrproc_t)xdr_receive_data,
>> + return_buffer);
>> + do_compare(rc, "callrpc", &buffer, return_buffer);
>
> As far as I can see the struct buffer is allocated in the
> xdr_receive_data function in lib/librpc01.c.
>
> So passing a pointer to a pointer to the struct buffer is right thing to
> do here.
>
> Or am I mistaken?
>
Thanks for your review,you are right,I make a mistake.
Now just fix the NULL pointer dereference,the return_buffer maybe NULL when
function callrpc is failed,then call do_compare will cause a "Segmentation
fault".
first initialize return_buffer = NULL,and then make a NULL check before
do_compare().for example:
if (!return_buffer)
fprintf(stderr, "callrpc is failed,the return_buffer is NULL\n");
do_compare(rc,.........)
Please review it again,thanks.
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list