Commit e3b4c3e
Jonathan Powell
Fix segfault when accessing fields/field_types on freed result
Add resultFreed check to rb_mysql_result_fetch_fields and
rb_mysql_result_fetch_field_types before accessing wrapper->result.
Additionally, eagerly populate fields when a result is created (for
non-streaming results) to prevent the issue from occurring at all.
This ensures fields are fetched before any iteration can free the
result.
The segfault occurs when:
1. A query returns 0 rows
2. Internal row caching iterates (0 iterations), never populating wrapper->fields
3. Result is freed after iteration completes
4. .fields is called, wrapper->fields is Qnil
5. mysql_num_fields(wrapper->result) accesses freed memory -> SEGFAULT
This check already exists in other functions (e.g., rb_mysql_result_each_)
but was missing in the fields accessor functions.
Based on fix for #14261 parent c79b3c1 commit e3b4c3e
1 file changed
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
939 | 939 | | |
940 | 940 | | |
941 | 941 | | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
942 | 945 | | |
943 | 946 | | |
944 | 947 | | |
| |||
958 | 961 | | |
959 | 962 | | |
960 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
961 | 967 | | |
962 | 968 | | |
963 | 969 | | |
| |||
1192 | 1198 | | |
1193 | 1199 | | |
1194 | 1200 | | |
| 1201 | + | |
1195 | 1202 | | |
1196 | 1203 | | |
1197 | 1204 | | |
| |||
1221 | 1228 | | |
1222 | 1229 | | |
1223 | 1230 | | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
1224 | 1239 | | |
1225 | 1240 | | |
1226 | 1241 | | |
| |||
0 commit comments