[patches] erl_interface: bug fixes, ei_print_term and show_term merge, and new ei_x_decode_* functions

Romain Lenglet rlenglet@REDACTED
Mon May 15 04:46:50 CEST 2006


Hello,


Please review the three attached patches, to apply in the 
following order, against the otp_src_R10B_2006-02-27 snapshot / 
erl_interface version 3.5.4:


- 01_ei_bugfixes.patch:

Corrects a number of bugs:
- in send_exit.c: malloc(len) instead of malloc(index) (index is 
always 0 at that point!), which made the function always 
return -1 when len>EISMALLBUF;
- when decoding references, only the first 3 bytes are read, but 
the index must be increment of the total size, not only 3;
- in ei_skip_term, the decoding of ERL_LARGE_BIG_EXT was boggus 
(the length returned by ei_get_type_internal in that case is 
*not* the length of the encoded term!);
- in ei_decode_trace, the index may have been updated even if the 
case decoding fails in the middle of decoding;
- same problem in print_term, for the decoding of ERL_LIST_EXT, 
ERL_SMALL_TUPLE_EXT and ERL_LARGE_TUPLE_EXT;
- in show_term, replace calls to ei_decode_skip_bignum by calls 
to ei_skip_term, which does the same job; remove 
ei_decode_skip_bignum.

Also adds some safety tests:
- when decoding a double (ERL_FLOAT_EXT), check that the last of 
the 31 bytes is a \0, to make sure that the sscanf does not scan 
after those 31 bytes;
- when decoding a fun, check that the buffer allocated for free 
variables is not NULL;
- when decoding a fun, check consistency of free variables data 
length.


- 02_ei_printtermshowtermmerged.patch:

Merges show_term into ei_print_term, and keeps the best of both 
functions.
Modifies the output format for binaries, atoms, pids, ports, 
refs, strings, and bignums	to better fit erlang's *_to_list bifs 
and io_lib's functions.
Replaces all uses of show_term by uses of ei_print_term.


- 03_ei_xdecode.patch:

Adds a ei_x_decode_* variant for every ei_decode_* function 
(resp. ei_x_get_type* / ei_get_type*), which takes an ei_x_buff 
*x argument instead of a const char *buf, int *index pair. This 
allows to check the index against the buffer size (x->buffsz) to 
prevent reading after the buffer end.
The ei_x_decode_* variants simply perform tests before every read 
(every get8(s), get16be(s), etc.), using a new check_get macro 
defined in putget.h.
The ei_decode_* unsafe variants are now implemented as stubs that 
call their corresponding ei_x_decode_* variant, in 
src/legacy/ei_decode_legacy.c.

The internal functions ei_show_recmsg and ei_show_sendmsg have 
been modified to call ei_x_decode_* instead of ei_decode_*, and 
this change is reflected in their new signature (they take 
ei_x_buff * arguments instead of const char *). Uses of 
ei_show_recmsg and ei_show_sendmsg have been accordingly 
modified in src/connect/*.c and src/not_used/*.c.

All code in src/decode/* and src/misc/* now uses the new 
ei_x_decode_* variants. Some "slave work" remains to be done, to 
replace all uses of ei_decode_* by uses of ei_x_decode_* in 
src/connect/*, src/prog/*, and src/registry/*.



I have checked that all patches compile correctly, without 
introducing new warnings.

Regards,

--
Romain LENGLET
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03_ei_xdecode.patch.gz
Type: application/x-gzip
Size: 13416 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060515/eeb8b570/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01_ei_bugfixes.patch.gz
Type: application/x-gzip
Size: 3296 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060515/eeb8b570/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02_ei_printtermshowtermmerged.patch.gz
Type: application/x-gzip
Size: 4487 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060515/eeb8b570/attachment-0002.bin>


More information about the erlang-bugs mailing list