Commit 406356e
committed
extmod/modlwip: Ensure socket is finalisable if error during creation.
Because socket objects have a finaliser they must be created carefully, in
case an exception is raised during the population of their members, eg
invalid input argument or out-of-memory when allocating additional arrays.
Prior to the fix in this commit, the finaliser would crash due to
`incoming.udp_raw.array` being an invalid pointer in the following cases:
- if a SOCK_RAW was created with a proto argument that was not an integer
- if a SOCK_DGRAM or SOCK_RAW was created where the allocation of
`lwip_incoming_packet_t` failed
- if an integer was passed in for the socket type but it was not one of
SOCK_STREAM, SOCK_DGRAM or SOCK_RAW
Furthermore, if the allocation of `lwip_incoming_packet_t` failed then it
may have led to corruption within lwIP when freeing `socket->pcb.raw`
because that PCB was not fully set up with its callbacks.
This commit fixes all of these issues by ensuring:
- `pcb.tcp` and `incoming.udp_raw.array` are initialised to NULL early on
- the proto argument is parsed before allocating the PCB
- the allocation of `lwip_incoming_packet_t` occurs befor allocating the
PCB
- `incoming.udp_raw.array` is checked for NULL in the finaliser code
The corresponding test (which already checked most of these causes of
failure) has been updated to include a previously-uncovered scenario.
Signed-off-by: Damien George <damien@micropython.org>1 parent b3d88cf commit 406356e
2 files changed
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| |||
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
941 | 944 | | |
| 945 | + | |
| 946 | + | |
942 | 947 | | |
943 | 948 | | |
944 | 949 | | |
945 | 950 | | |
946 | 951 | | |
947 | 952 | | |
948 | 953 | | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
949 | 957 | | |
950 | 958 | | |
951 | 959 | | |
952 | 960 | | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
953 | 964 | | |
954 | 965 | | |
955 | 966 | | |
| |||
963 | 974 | | |
964 | 975 | | |
965 | 976 | | |
| 977 | + | |
966 | 978 | | |
967 | 979 | | |
968 | 980 | | |
969 | 981 | | |
970 | 982 | | |
971 | | - | |
972 | | - | |
| 983 | + | |
973 | 984 | | |
974 | 985 | | |
975 | 986 | | |
976 | 987 | | |
977 | | - | |
978 | 988 | | |
979 | 989 | | |
980 | 990 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| |||
0 commit comments