Skip to content
Snippets Groups Projects

Sanitise unsafe functions, GNUC annotations

Merged Ghost User requested to merge wire-unsafe-funcs into master

This is an attempt to sanitise unsafe functions in libknot API which allow easy out-of-bound reads or undefined return value. The other part is annotating most used functions with appropriate attributes.

Merge request reports

Approval is optional

Merged by avatar (Apr 14, 2025 8:22am UTC)

Merge details

  • Changes merged into master with 9b31291e.
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
30 30 #define _public_ __attribute__((visibility("default")))
31 31 #define _hidden_ __attribute__((visibility("hidden")))
32 32
33 /*! \brief GNU C function attributes. */
34 #if __GNUC__ >= 3
35 #define _pure_ __attribute__ ((pure))
36 #define _const_ __attribute__ ((const))
37 #define _noreturn_ __attribute__ ((noreturn))
38 #define _malloc_ __attribute__ ((malloc))
39 #define _mustcheck_ __attribute__ ((warn_unused_result))
  • 50 51 * \retval KNOT_EMALF
    51 52 * \retval KNOT_ESPACE
    52 53 */
    54 _pure_ _mustcheck_
    53 55 int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
    • @mvavrusa Do you know whether pure annotation works well with pointers? Because if the comparison of parameters is done as with scalar values, then this is wrong.

  • https://lwn.net/Articles/285332/

    
    A counter-example of a non-pure function is the strcpy() function. This function takes two pointers as parameters. It accesses the latter to read the source string, and the former to write to the destination string. As I said, the memory areas pointed to by the parameters are not parameters on their own, but are considered global memory and, in that function, global memory is not only accessed for reading, but also for writing. The return value derives directly from the parameters (it is the same as the first parameter), but global memory is affected by the side effect of strcpy(), making it not pure.```
  • Then it should be fine. :-)

  • Daniel Salzman Title changed from WIP: sanitise unsafe functions, GNUC annotations to Sanitise unsafe functions, GNUC annotations

    Title changed from WIP: sanitise unsafe functions, GNUC annotations to Sanitise unsafe functions, GNUC annotations

  • Daniel Salzman mentioned in commit 6369a2ed

    mentioned in commit 6369a2ed

  • Daniel Salzman Status changed to merged

    Status changed to merged

  • Daniel Salzman removed milestone

    removed milestone

  • Please register or sign in to reply
    Loading