Commit 2be117a
authored
This change addresses the following ASAN error:
```
==36597==ERROR: AddressSanitizer: heap-use-after-free on address 0x512000396ba8 at pc 0x7fcad5cbad9f bp 0x7fff19739af0 sp 0x7fff19739ae8
WRITE of size 8 at 0x512000396ba8 thread T0
[643/756] 36600=optparse/test_summary
#0 0x7fcad5cbad9e in free_fast_fallback_getaddrinfo_entry /home/runner/work/ruby-dev-builder/ruby-dev-builder/ext/socket/raddrinfo.c:3046:22
#1 0x7fcad5c9fb48 in fast_fallback_inetsock_cleanup /home/runner/work/ruby-dev-builder/ruby-dev-builder/ext/socket/ipsocket.c:1179:17
#2 0x7fcadf3b611a in rb_ensure /home/runner/work/ruby-dev-builder/ruby-dev-builder/eval.c:1081:5
#3 0x7fcad5c9b44b in rsock_init_inetsock /home/runner/work/ruby-dev-builder/ruby-dev-builder/ext/socket/ipsocket.c:1289:20
#4 0x7fcad5ca22b8 in tcp_init /home/runner/work/ruby-dev-builder/ruby-dev-builder/ext/socket/tcpsocket.c:76:12
#5 0x7fcadf83ba70 in vm_call0_cfunc_with_frame /home/runner/work/ruby-dev-builder/ruby-dev-builder/./vm_eval.c:164:15
...
```
A `struct fast_fallback_getaddrinfo_shared` is shared between the main thread and two child threads.
This struct contains an array of `fast_fallback_getaddrinfo_entry`.
`fast_fallback_getaddrinfo_entry` and `fast_fallback_getaddrinfo_shared` were freed separately, and if `fast_fallback_getaddrinfo_shared` was freed first and then an attempt was made to free a `fast_fallback_getaddrinfo_entry`, a `heap-use-after-free` could occur.
This change avoids that possibility by separating the deallocation of the addrinfo memory held by `fast_fallback_getaddrinfo_entry` from the access and lifecycle of the `fast_fallback_getaddrinfo_entry` itself.
1 parent 36c64b3 commit 2be117a
2 files changed
+17
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1159 | 1159 | | |
1160 | 1160 | | |
1161 | 1161 | | |
1162 | | - | |
| 1162 | + | |
| 1163 | + | |
1163 | 1164 | | |
1164 | 1165 | | |
1165 | 1166 | | |
1166 | 1167 | | |
1167 | | - | |
1168 | | - | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
1169 | 1175 | | |
1170 | 1176 | | |
1171 | 1177 | | |
| |||
1175 | 1181 | | |
1176 | 1182 | | |
1177 | 1183 | | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
| 1184 | + | |
1181 | 1185 | | |
1182 | 1186 | | |
1183 | 1187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3038 | 3038 | | |
3039 | 3039 | | |
3040 | 3040 | | |
3041 | | - | |
3042 | | - | |
3043 | | - | |
3044 | | - | |
3045 | | - | |
3046 | | - | |
3047 | | - | |
3048 | | - | |
3049 | | - | |
3050 | | - | |
3051 | 3041 | | |
3052 | 3042 | | |
3053 | 3043 | | |
3054 | 3044 | | |
3055 | 3045 | | |
3056 | | - | |
| 3046 | + | |
| 3047 | + | |
3057 | 3048 | | |
3058 | 3049 | | |
3059 | 3050 | | |
| |||
3102 | 3093 | | |
3103 | 3094 | | |
3104 | 3095 | | |
3105 | | - | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
3106 | 3100 | | |
3107 | 3101 | | |
3108 | 3102 | | |
3109 | 3103 | | |
3110 | | - | |
3111 | | - | |
3112 | | - | |
| 3104 | + | |
3113 | 3105 | | |
3114 | 3106 | | |
3115 | 3107 | | |
| |||
0 commit comments