libctf: fix double-free on ctf_compress_write error path
[deliverable/binutils-gdb.git] / libctf / ChangeLog
1 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
2
3 * ctf-create.c (ctf_compress_write): Fix double-free.
4
5 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
6
7 * ctf-archive.c (ctf_arc_write): Split off, and reimplement in terms
8 of...
9 (ctf_arc_write_fd): ... this new function.
10 * ctf-create.c (ctf_write_mem): New.
11
12 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
13
14 * ctf-impl.h (ctf_str_atom_t) <csa_offset>: New field.
15 (ctf_file_t) <ctf_syn_ext_strtab>: Likewise.
16 (ctf_str_add_ref): Name the last arg.
17 (ctf_str_add_external) New.
18 (ctf_str_add_strraw_explicit): Likewise.
19 (ctf_simple_open_internal): Likewise.
20 (ctf_bufopen_internal): Likewise.
21
22 * ctf-string.c (ctf_strraw_explicit): Split from...
23 (ctf_strraw): ... here, with new support for ctf_syn_ext_strtab.
24 (ctf_str_add_ref_internal): Return the atom, not the
25 string.
26 (ctf_str_add): Adjust accordingly.
27 (ctf_str_add_ref): Likewise. Move up in the file.
28 (ctf_str_add_external): New: update the csa_offset.
29 (ctf_str_count_strtab): Only account for strings with no csa_offset
30 in the internal strtab length.
31 (ctf_str_write_strtab): If the csa_offset is set, update the
32 string's refs without writing the string out, and update the
33 ctf_syn_ext_strtab. Make OOM handling less ugly.
34 * ctf-create.c (struct ctf_sort_var_arg_cb): New.
35 (ctf_update): Handle failure to populate the strtab. Pass in the
36 new ctf_sort_var arg. Adjust for ctf_syn_ext_strtab addition.
37 Call ctf_simple_open_internal, not ctf_simple_open.
38 (ctf_sort_var): Call ctf_strraw_explicit rather than looking up
39 strings by hand.
40 * ctf-hash.c (ctf_hash_insert_type): Likewise (but using
41 ctf_strraw). Adjust to diagnose ECTF_STRTAB nonetheless.
42 * ctf-open.c (init_types): No longer filter out ECTF_STRTAB.
43 (ctf_file_close): Destroy the ctf_syn_ext_strtab.
44 (ctf_simple_open): Rename to, and reimplement as a wrapper around...
45 (ctf_simple_open_internal): ... this new function, which calls
46 ctf_bufopen_internal.
47 (ctf_bufopen): Rename to, and reimplement as a wrapper around...
48 (ctf_bufopen_internal): ... this new function, which sets
49 ctf_syn_ext_strtab.
50
51 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
52
53 * ctf_types.c (ctf_type_iter_all): New.
54
55 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
56
57 * ctf-open.c (init_symtab): Check for overflow against the right
58 section.
59 (upgrade_header): Set cth_objtidxoff, cth_funcidxoff to zero-length.
60 (upgrade_types_v1): Note that these sections are not checked.
61 (flip_header): Endian-swap the header fields.
62 (flip_ctf): Endian-swap the sections.
63 (flip_objts): Update comment.
64 (ctf_bufopen): Check header offsets and alignment for validity.
65
66 2019-07-13 Nick Alcock <nick.alcock@oracle.com>
67
68 * ctf-open-bfd.c: Add <assert.h>.
69 (ctf_bfdopen_ctfsect): Open string and symbol tables using
70 techniques borrowed from bfd_elf_sym_name.
71 (ctf_new_archive_internal): Improve comment.
72 * ctf-archive.c (ctf_arc_close): Do not free the ctfi_strsect.
73 * ctf-open.c (ctf_bufopen): Allow opening with a string section but
74 no symbol section, but not vice versa.
75
76 2019-07-08 Nick Alcock <nick.alcock@oracle.com>
77
78 * ctf-impl.h (ctf_file_t): New field ctf_openflags.
79 * ctf-open.c (ctf_bufopen): Set it. No longer dump header offsets.
80 * ctf-dump.c (dump_header): New function, dump the CTF header.
81 (ctf_dump): Call it.
82 (ctf_dump_header_strfield): New function.
83 (ctf_dump_header_sectfield): Likewise.
84
85 2019-07-06 Nick Alcock <nick.alcock@oracle.com>
86
87 * ctf-impl.h (ctf_file_t): New fields ctf_header, ctf_dynbase,
88 ctf_cuname, ctf_dyncuname: ctf_base and ctf_buf are no longer const.
89 * ctf-open.c (ctf_set_base): Preserve the gap between ctf_buf and
90 ctf_base: do not assume that it is always sizeof (ctf_header_t).
91 Print out ctf_cuname: only print out ctf_parname if set.
92 (ctf_free_base): Removed, ctf_base is no longer freed: free
93 ctf_dynbase instead.
94 (ctf_set_version): Fix spacing.
95 (upgrade_header): New, in-place header upgrading.
96 (upgrade_types): Rename to...
97 (upgrade_types_v1): ... this. Free ctf_dynbase, not ctf_base. No
98 longer track old and new headers separately. No longer allow for
99 header sizes explicitly: squeeze the headers out on upgrade (they
100 are preserved in fp->ctf_header). Set ctf_dynbase, ctf_base and
101 ctf_buf explicitly. Use ctf_free, not ctf_free_base.
102 (upgrade_types): New, also handle ctf_parmax updating.
103 (flip_header): Flip ctf_cuname.
104 (flip_types): Flip BUF explicitly rather than deriving BUF from
105 BASE.
106 (ctf_bufopen): Store the header in fp->ctf_header. Correct minimum
107 required alignment of objtoff and funcoff. No longer store it in
108 the ctf_buf unless that buf is derived unmodified from the input.
109 Set ctf_dynbase where ctf_base is dynamically allocated. Drop locals
110 that duplicate fields in ctf_file: move allocation of ctf_file
111 further up instead. Call upgrade_header as needed. Move
112 version-specific ctf_parmax initialization into upgrade_types. More
113 concise error handling.
114 (ctf_file_close): No longer test for null pointers before freeing.
115 Free ctf_dyncuname, ctf_dynbase, and ctf_header. Do not call
116 ctf_free_base.
117 (ctf_cuname): New.
118 (ctf_cuname_set): New.
119 * ctf-create.c (ctf_update): Populate ctf_cuname.
120 (ctf_gzwrite): Write out the header explicitly. Remove obsolescent
121 comment.
122 (ctf_write): Likewise.
123 (ctf_compress_write): Get the header from ctf_header, not ctf_base.
124 Fix the compression length: fp->ctf_size never counted the CTF
125 header. Simplify the compress call accordingly.
126
127 2019-07-11 Hans-Peter Nilsson <hp@bitrange.com>
128
129 * ctf-endian.h: Don't assume htole64 and le64toh are always
130 present if HAVE_ENDIAN_H; also check if htole64 is defined.
131 [!WORDS_BIGENDIAN] (htole64, le64toh): Define as identity,
132 not bswap_identity_64.
133
134 2019-09-18 Alan Modra <amodra@gmail.com>
135
136 * ctf-open-bfd.c: Update throughout for bfd section macro changes.
137
138 2019-09-09 Phil Blundell <pb@pbcl.net>
139
140 binutils 2.33 branch created.
141
142 2019-07-18 Nick Alcock <nick.alcock@oracle.com>
143
144 * ctf-types.c (ctf_type_aname_raw): New.
145 (ctf_func_type_info): Likewise.
146 (ctf_func_type_args): Likewise.
147 * ctf-error.c (_ctf_errlist): Fix description.
148 * ctf-lookup.c: Fix file description.
149
150 2019-06-28 Nick Alcock <nick.alcock@oracle.com>
151
152 * ctf-create.c (ctf_create): Fix off-by-one error.
153
154 2019-06-28 Nick Alcock <nick.alcock@oracle.com>
155
156 * ctf-impl.h: (struct ctf_strs_writable): New, non-const version of
157 struct ctf_strs.
158 (struct ctf_dtdef): Note that dtd_data.ctt_name is unpopulated.
159 (struct ctf_str_atom): New, disambiguated single string.
160 (struct ctf_str_atom_ref): New, points to some other location that
161 references this string's offset.
162 (struct ctf_file): New members ctf_str_atoms and ctf_str_num_refs.
163 Remove member ctf_dtvstrlen: we no longer track the total strlen
164 as we add strings.
165 (ctf_str_create_atoms): Declare new function in ctf-string.c.
166 (ctf_str_free_atoms): Likewise.
167 (ctf_str_add): Likewise.
168 (ctf_str_add_ref): Likewise.
169 (ctf_str_rollback): Likewise.
170 (ctf_str_purge_refs): Likewise.
171 (ctf_str_write_strtab): Likewise.
172 (ctf_realloc): Declare new function in ctf-util.c.
173
174 * ctf-open.c (ctf_bufopen): Create the atoms table.
175 (ctf_file_close): Destroy it.
176 * ctf-create.c (ctf_update): Copy-and-free it on update. No longer
177 special-case the position of the parname string. Construct the
178 strtab by calling ctf_str_add_ref and ctf_str_write_strtab after the
179 rest of each buffer element is constructed, not via open-coding:
180 realloc the CTF buffer and append the strtab to it. No longer
181 maintain ctf_dtvstrlen. Sort the variable entry table later, after
182 strtab construction.
183 (ctf_copy_membnames): Remove: integrated into ctf_copy_{s,l,e}members.
184 (ctf_copy_smembers): Drop the string offset: call ctf_str_add_ref
185 after buffer element construction instead.
186 (ctf_copy_lmembers): Likewise.
187 (ctf_copy_emembers): Likewise.
188 (ctf_create): No longer maintain the ctf_dtvstrlen.
189 (ctf_dtd_delete): Likewise.
190 (ctf_dvd_delete): Likewise.
191 (ctf_add_generic): Likewise.
192 (ctf_add_enumerator): Likewise.
193 (ctf_add_member_offset): Likewise.
194 (ctf_add_variable): Likewise.
195 (membadd): Likewise.
196 * ctf-util.c (ctf_realloc): New, wrapper around realloc that aborts
197 if there are active ctf_str_num_refs.
198 (ctf_strraw): Move to ctf-string.c.
199 (ctf_strptr): Likewise.
200 * ctf-string.c: New file, strtab manipulation.
201
202 * Makefile.am (libctf_a_SOURCES): Add it.
203 * Makefile.in: Regenerate.
204
205 2019-06-28 Nick Alcock <nick.alcock@oracle.com>
206
207 * ctf-impl.h (ctf_hash_iter_f): New.
208 (ctf_dynhash_iter): New declaration.
209 (ctf_dynhash_iter_remove): New declaration.
210 * ctf-hash.c (ctf_dynhash_iter): Define.
211 (ctf_dynhash_iter_remove): Likewise.
212 (ctf_hashtab_traverse): New.
213 (ctf_hashtab_traverse_remove): Likewise.
214 (struct ctf_traverse_cb_arg): Likewise.
215 (struct ctf_traverse_remove_cb_arg): Likewise.
216
217 2019-06-28 Nick Alcock <nick.alcock@oracle.com>
218
219 * ctf-hash.c (ctf_dynhash_remove): Call with a mocked-up element.
220
221 2019-06-28 Nick Alcock <nick.alcock@oracle.com>
222
223 * ctf-dump.c (ctf_dump_format_type): Prefix hex strings with 0x.
224 (ctf_dump_funcs): Likewise.
225
226 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
227
228 * ctf-open-bfd.c: Add swap.h and ctf-endian.h.
229 (ctf_fdopen): Check for endian-swapped raw CTF magic, and
230 little-endian CTF archive magic. Do not check the CTF version:
231 ctf_simple_open does that in endian-safe ways. Do not dereference
232 null pointers on open failure.
233
234 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
235
236 * ctf-open.c (get_vbytes_common): Return the new slice size.
237 (ctf_bufopen): Flip the endianness of the CTF-section header copy.
238 Remember to copy in the CTF data when opening an uncompressed
239 foreign-endian CTF file. Prune useless variable manipulation.
240
241 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
242
243 * ctf-open.c (ctf_types): Fail when unidentified type kinds are
244 seen.
245
246 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
247
248 * ctf-open.c (ctf_bufopen): Dump header offsets into the debugging
249 output.
250
251 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
252
253 * ctf-subr.c (_PAGESIZE): Remove.
254 (ctf_data_alloc): Likewise.
255 (ctf_data_free): Likewise.
256 (ctf_data_protect): Likewise.
257 * ctf-impl.h: Remove declarations.
258 * ctf-create.c (ctf_update): No longer call ctf_data_protect: use
259 ctf_free, not ctf_data_free.
260 (ctf_compress_write): Use ctf_data_alloc, not ctf_alloc. Free
261 the buffer again on compression error.
262 * ctf-open.c (ctf_set_base): No longer track the size: call
263 ctf_free, not ctf_data_free.
264 (upgrade_types): Likewise. Call ctf_alloc, not ctf_data_alloc.
265 (ctf_bufopen): Likewise. No longer call ctf_data_protect.
266
267 2019-06-19 Nick Alcock <nick.alcock@oracle.com>
268
269 * ctf-create.c (ctf_dtd_insert): Pass on error returns from
270 ctf_dynhash_insert.
271 (ctf_dvd_insert): Likewise.
272 (ctf_add_generic): Likewise.
273 (ctf_add_variable): Likewise.
274 * ctf-impl.h: Adjust declarations.
275
276 2019-06-14 Alan Modra <amodra@gmail.com>
277
278 * configure: Regenerate.
279
280 2019-06-06 Nick Alcock <nick.alcock@oracle.com>
281
282 * ctf-decls.h: Include <libiberty.h>.
283 * ctf-lookup.c (ctf_lookup_by_name): Call xstrndup(), not strndup().
284
285 2019-06-06 Nick Alcock <nick.alcock@oracle.com>
286
287 * ctf-dump.c (ctf_dump_format_type): Cast size_t's used in printf()s.
288 (ctf_dump_objts): Likewise.
289 (ctf_dump_funcs): Likewise.
290 (ctf_dump_member): Likewise.
291 (ctf_dump_str): Likewise.
292
293 2019-06-06 Nick Alcock <nick.alcock@oracle.com>
294
295 * ctf-archive.c (arc_mmap_header): Mark fd as potentially unused.
296 * ctf-subr.c (ctf_data_protect): Mark both args as potentially unused.
297
298 2019-06-05 Nick Alcock <nick.alcock@oracle.com>
299
300 * ctf-archive.c (ctf_arc_write): Eschew %zi format specifier.
301 (ctf_arc_open_by_offset): Likewise.
302 * ctf-create.c (ctf_add_type): Likewise.
303
304 2019-06-04 Tom Tromey <tromey@adacore.com>
305
306 * ctf-create.c (ctf_add_encoded, ctf_add_slice)
307 (ctf_add_member_offset): Use CHAR_BIT, not NBBY.
308
309 2019-06-04 Nick Alcock <nick.alcock@oracle.com>
310
311 * configure.ac: Check for O_CLOEXEC.
312 * ctf-decls.h (O_CLOEXEC): Define (to 0), if need be.
313 * config.h.in: Regenerate.
314 * configure: Likewise.
315
316 2019-06-04 Nick Alcock <nick.alcock@oracle.com>
317
318 * qsort_r.c: Rename to...
319 * ctf-qsort_r.c: ... this.
320 (_quicksort): Define to ctf_qsort_r.
321 * ctf-decls.h (qsort_r): Remove.
322 (ctf_qsort_r): Add.
323 (struct ctf_qsort_arg): New, transport the real ARG and COMPAR.
324 (ctf_qsort_compar_thunk): Rearrange the arguments to COMPAR.
325 * Makefile.am (libctf_a_LIBADD): Remove.
326 (libctf_a_SOURCES): New, add ctf-qsort_r.c.
327 * ctf-archive.c (ctf_arc_write): Call ctf_qsort_r, not qsort_r.
328 * ctf-create.c (ctf_update): Likewise.
329 * configure.ac: Check for BSD versus GNU qsort_r signature.
330 * Makefile.in: Regenerate.
331 * config.h.in: Likewise.
332 * configure: Likewise.
333
334 2019-06-03 Nick Alcock <nick.alcock@oracle.com>
335
336 * ctf-dump.c (ctf_dump_funcs): Free in the right place.
337
338 2019-05-29 Nick Alcock <nick.alcock@oracle.com>
339
340 * Makefile.am (ZLIB): New.
341 (ZLIBINC): Likewise.
342 (AM_CFLAGS): Use them.
343 (libctf_a_LIBADD): New, for LIBOBJS.
344 * configure.ac: Check for zlib, endian.h, and qsort_r.
345 * ctf-endian.h: New, providing htole64 and le64toh.
346 * swap.h: Code style fixes.
347 (bswap_identity_64): New.
348 * qsort_r.c: New, from gnulib (with one added #include).
349 * ctf-decls.h: New, providing a conditional qsort_r declaration,
350 and unconditional definitions of MIN and MAX.
351 * ctf-impl.h: Use it. Do not use <sys/errno.h>.
352 (ctf_set_errno): Now returns unsigned long.
353 * ctf-util.c (ctf_set_errno): Adjust here too.
354 * ctf-archive.c: Use ctf-endian.h.
355 (ctf_arc_open_by_offset): Use memset, not bzero. Drop cts_type,
356 cts_flags and cts_offset.
357 (ctf_arc_write): Drop debugging dependent on the size of off_t.
358 * ctf-create.c: Provide a definition of roundup if not defined.
359 (ctf_create): Drop cts_type, cts_flags and cts_offset.
360 (ctf_add_reftype): Do not check if type IDs are below zero.
361 (ctf_add_slice): Likewise.
362 (ctf_add_typedef): Likewise.
363 (ctf_add_member_offset): Cast error-returning ssize_t's to size_t
364 when known error-free. Drop CTF_ERR usage for functions returning
365 int.
366 (ctf_add_member_encoded): Drop CTF_ERR usage for functions returning
367 int.
368 (ctf_add_variable): Likewise.
369 (enumcmp): Likewise.
370 (enumadd): Likewise.
371 (membcmp): Likewise.
372 (ctf_add_type): Likewise. Cast error-returning ssize_t's to size_t
373 when known error-free.
374 * ctf-dump.c (ctf_is_slice): Drop CTF_ERR usage for functions
375 returning int: use CTF_ERR for functions returning ctf_type_id.
376 (ctf_dump_label): Likewise.
377 (ctf_dump_objts): Likewise.
378 * ctf-labels.c (ctf_label_topmost): Likewise.
379 (ctf_label_iter): Likewise.
380 (ctf_label_info): Likewise.
381 * ctf-lookup.c (ctf_func_args): Likewise.
382 * ctf-open.c (upgrade_types): Cast to size_t where appropriate.
383 (ctf_bufopen): Likewise. Use zlib types as needed.
384 * ctf-types.c (ctf_member_iter): Drop CTF_ERR usage for functions
385 returning int.
386 (ctf_enum_iter): Likewise.
387 (ctf_type_size): Likewise.
388 (ctf_type_align): Likewise. Cast to size_t where appropriate.
389 (ctf_type_kind_unsliced): Likewise.
390 (ctf_type_kind): Likewise.
391 (ctf_type_encoding): Likewise.
392 (ctf_member_info): Likewise.
393 (ctf_array_info): Likewise.
394 (ctf_enum_value): Likewise.
395 (ctf_type_rvisit): Likewise.
396 * ctf-open-bfd.c (ctf_bfdopen): Drop cts_type, cts_flags and
397 cts_offset.
398 (ctf_simple_open): Likewise.
399 (ctf_bfdopen_ctfsect): Likewise. Set cts_size properly.
400 * Makefile.in: Regenerate.
401 * aclocal.m4: Likewise.
402 * config.h: Likewise.
403 * configure: Likewise.
404
405 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
406
407 * configure.in: Check for bfd_section_from_elf_index.
408 * configure: Regenerate.
409 * config.h.in [HAVE_BFD_ELF]: Likewise.
410 * libctf/ctf_open_bfd (ctf_bfdopen_ctfsect): Use it.
411 abfd is potentially unused now.
412
413 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
414
415 * Makefile.am: New.
416 * Makefile.in: Regenerated.
417 * config.h.in: Likewise.
418 * aclocal.m4: Likewise.
419 * configure: Likewise.
420
421 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
422
423 * ctf-dump.c: New.
424
425 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
426
427 * ctf-labels.c: New.
428
429 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
430
431 * ctf-impl.h (_libctf_version): New declaration.
432 * ctf-subr.c (_libctf_version): Define it.
433 (ctf_version): New.
434
435 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
436
437 * ctf-create.c (enumcmp): New.
438 (enumadd): Likewise.
439 (membcmp): Likewise.
440 (membadd): Likewise.
441 (ctf_add_type): Likewise.
442
443 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
444
445 * ctf-lookup.c (isqualifier): New.
446 (ctf_lookup_by_name): Likewise.
447 (struct ctf_lookup_var_key): Likewise.
448 (ctf_lookup_var): Likewise.
449 (ctf_lookup_variable): Likewise.
450 (ctf_lookup_symbol_name): Likewise.
451 (ctf_lookup_by_symbol): Likewise.
452 (ctf_func_info): Likewise.
453 (ctf_func_args): Likewise.
454
455 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
456
457 * ctf-decl.c: New file.
458 * ctf-types.c: Likewise.
459 * ctf-impl.h: New declarations.
460
461 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
462
463 * ctf-open-bfd.c: New file.
464 * ctf-open.c (ctf_close): New.
465 * ctf-impl.h: Include bfd.h.
466 (ctf_file): New members ctf_data_mmapped, ctf_data_mmapped_len.
467 (ctf_archive_internal): New members ctfi_abfd, ctfi_data,
468 ctfi_bfd_close.
469 (ctf_bfdopen_ctfsect): New declaration.
470 (_CTF_SECTION): likewise.
471
472 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
473
474 * ctf-archive.c: New.
475 * ctf-impl.h (ctf_archive_internal): New type.
476 (ctf_arc_open_internal): New declaration.
477 (ctf_arc_bufopen): Likewise.
478 (ctf_arc_close_internal): Likewise.
479
480 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
481
482 * ctf-open.c: New file.
483 * swap.h: Likewise.
484
485 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
486
487 * ctf-create.c: New file.
488 * ctf-lookup.c: New file.
489
490 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
491
492 * ctf-impl.h: New definitions and declarations for type creation
493 and lookup.
494
495 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
496
497 * ctf-hash.c: New file.
498 * ctf-impl.h: New declarations.
499
500 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
501
502 * ctf-error.c: New file.
503
504 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
505
506 * ctf-util.c: New file.
507 * elf.h: Likewise.
508 * ctf-impl.h: Include it, and add declarations.
509
510 2019-05-28 Nick Alcock <nick.alcock@oracle.com>
511
512 * ctf-impl.h: New file.
513 * ctf-subr.c: New file.
514
515 \f
516 Local Variables:
517 mode: change-log
518 left-margin: 8
519 fill-column: 76
520 version-control: never
521 End:
This page took 0.041576 seconds and 4 git commands to generate.