Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide private functions from createrepo_c library #407

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ppisar
Copy link
Contributor

@ppisar ppisar commented Nov 24, 2023

The library exported 274 symbols. However, many of them were not declared in any public header file, hence application were not supposed to use them. In other words, the library offered functions which were not part of an API. That was not good because:

These private functions enlarged an attack surface. These private functions polluted binary interface and triggered warnigs by ABI checkers (e.g. when libXML-2.12.0 changed xmlParserCtxt structure).
These private functions could fool a user into calling them and that would increase a pressure on broadening createrepo_c API.

I reviewed all the 274 symbols and hid 52 of them:

cr_char_handler
cr_cktype_from_zck
cr_db_add_filelists_pkg
cr_db_add_other_pkg
cr_db_add_primary_pkg
cr_db_destroy_filelists_statements
cr_db_destroy_other_statements
cr_db_destroy_primary_statements
cr_db_prepare_filelists_statements
cr_db_prepare_other_statements
cr_db_prepare_primary_statements
cr_destroy_metadata_hashtable
cr_free_values
cr_get_compressed_content_stat
cr_new_metadata_hashtable
cr_newpkgcb
cr_package_copy_into
cr_prestodeltatask_free
cr_remove_dir_cb
cr_xml_dump_delta
cr_xml_dump_filelists_chunk
cr_xml_dump_filelists_items
cr_xml_dump_files
cr_xml_dump_int
cr_xml_dump_other_changelog
cr_xml_dump_other_items
cr_xml_dump_repomd_body
cr_xml_dump_repomd_record
cr_xml_dump_updatecollectionmodule
cr_xml_dump_updatecollectionpackages
cr_xml_dump_updateinfo_body
cr_xml_dump_updateinforecord_internal
cr_xml_dump_updateinforecord_pkglist
cr_xml_dump_updateinforecord_references
cr_xmlfile_write_xml_footer
cr_xmlfile_write_xml_header
cr_xmlNewProp
cr_xmlNewTextChild
cr_xml_parse_filelists_internal
cr_xml_parse_other_internal
cr_xml_parse_primary_internal
cr_xml_parser_data
cr_xml_parser_data_free
cr_xml_parser_generic
cr_xml_parser_generic_from_string
cr_xml_parser_strtoll
cr_xml_parser_warning
filelists_parser_data_new
other_parser_data_new
prepare_split_media_baseurl
primary_parser_data_new
unescape_ampersand_from_values

I kept these 10 private symbols because they are called either from createrepo_c program or from a Python binding:

cr_compress_groupfile
cr_delayed_dump_run
cr_delayed_dump_set
cr_distrotag_new
cr_dumper_thread
cr_metadata_load_modulemd
cr_metadata_modulemd
cr_repomd_compare
cr_xml_dump_primary_base_items
cr_xml_dump_primary_dump_pco

This patch minimizes a symbol table by making the private functions static or by setting their visibility to a hidden state. As result, they disappear from the library binary interface.

The library exported 274 symbols. However, many of them were not declared in
any public header file, hence application were not supposed to use
them. In other words, the library offered functions which were not
part of an API. That was not good because:

These private functions enlarged an attack surface.
These private functions polluted binary interface and triggered warnigs
by ABI checkers (e.g. when libXML-2.12.0 changed xmlParserCtxt
structure).
These private functions could fool a user into calling them and that
would increase a pressure on broadening createrepo_c API.

I reviewed all the 274 symbols and hid 52 of them:

cr_char_handler
cr_cktype_from_zck
cr_db_add_filelists_pkg
cr_db_add_other_pkg
cr_db_add_primary_pkg
cr_db_destroy_filelists_statements
cr_db_destroy_other_statements
cr_db_destroy_primary_statements
cr_db_prepare_filelists_statements
cr_db_prepare_other_statements
cr_db_prepare_primary_statements
cr_destroy_metadata_hashtable
cr_free_values
cr_get_compressed_content_stat
cr_new_metadata_hashtable
cr_newpkgcb
cr_package_copy_into
cr_prestodeltatask_free
cr_remove_dir_cb
cr_xml_dump_delta
cr_xml_dump_filelists_chunk
cr_xml_dump_filelists_items
cr_xml_dump_files
cr_xml_dump_int
cr_xml_dump_other_changelog
cr_xml_dump_other_items
cr_xml_dump_repomd_body
cr_xml_dump_repomd_record
cr_xml_dump_updatecollectionmodule
cr_xml_dump_updatecollectionpackages
cr_xml_dump_updateinfo_body
cr_xml_dump_updateinforecord_internal
cr_xml_dump_updateinforecord_pkglist
cr_xml_dump_updateinforecord_references
cr_xmlfile_write_xml_footer
cr_xmlfile_write_xml_header
cr_xmlNewProp
cr_xmlNewTextChild
cr_xml_parse_filelists_internal
cr_xml_parse_other_internal
cr_xml_parse_primary_internal
cr_xml_parser_data
cr_xml_parser_data_free
cr_xml_parser_generic
cr_xml_parser_generic_from_string
cr_xml_parser_strtoll
cr_xml_parser_warning
filelists_parser_data_new
other_parser_data_new
prepare_split_media_baseurl
primary_parser_data_new
unescape_ampersand_from_values

I kept these 10 private symbols because they are called either from
createrepo_c program or from a Python binding:

cr_compress_groupfile
cr_delayed_dump_run
cr_delayed_dump_set
cr_distrotag_new
cr_dumper_thread
cr_metadata_load_modulemd
cr_metadata_modulemd
cr_repomd_compare
cr_xml_dump_primary_base_items
cr_xml_dump_primary_dump_pco

This patch minimizes a symbol table by making the private functions
static or by setting their visibility to a hidden state. As result,
they disappear from the library binary interface.
@ppisar
Copy link
Contributor Author

ppisar commented Nov 24, 2023

Oh my god. "make test" and "make tests" differ.

@ppisar ppisar marked this pull request as draft November 24, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant