-
Notifications
You must be signed in to change notification settings - Fork 403
Description
See the test program at https://gist.github.com/IlyaM/5715139 which is based on documentation in comments in tp.h. The test program does a query in space 0 by string key "0e72ae1a-d0be-4e49-aeb9-aebea074363c" . If the test database does contain some tuple with such key then the program ends up hanging waiting for a reply from tarantool. The underlying bug is caused by wrong call to tp_ensure inside of while loop which is written exactly as suggested in the documentation. In such program tp.h ends up allocating insufficient memory for the next read from network what causes the program:
a) to potentially corrupt memory because read() call reads more bytes then was allocated in the buffer;
b) to set internal pointers in tp struct such that the code in while loop thinks it needs to read more data from network when in fact the whole reply have been read.
If I change tp_ensure line to the following then the code does seem to work correctly:
ssize_t new_size = tp_ensure(&rep, to_read + tp_size(&rep));
What suggests that the example in the documentation is wrong.
P.S. Also I'd change example in comments for tp_select to pass non-zero value for limit parameter. I've spent significant time trying to understand why I'm not getting any results because of this.