================ @@ -934,6 +934,76 @@ Check calls to various UNIX/Posix functions: ``open, pthread_once, calloc, mallo .. literalinclude:: checkers/unix_api_example.c :language: c +.. _unix-Errno: + +unix.Errno (C) +"""""""""""""" + +Check for improper use of ``errno``. +This checker implements partially CERT rule +`ERR30-C. Set errno to zero before calling a library function known to set errno, +and check errno only after the function returns a value indicating failure +<https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152351>`_. +The checker can find the first read of ``errno`` after successful standard +function calls. + +The C and POSIX standards often do not define if a standard library function +may change value of ``errno`` if the call does not fail. +Therefore, ``errno`` should only be used if it is known from the return value +of a function that the call has failed. +There are exceptions to this rule (for example ``strtol``) but the affected +functions are not yet supported by the checker. +The return values for the failure cases are documented in the standard Linux man +pages of the functions and in the `POSIX standard <https://pubs.opengroup.org/onlinepubs/9699919799/>`_. + +.. code-block:: c + + int unsafe_errno_read(int sock, void *data, int data_size) { + if (send(sock, data, data_size, 0) != data_size) { + // 'send' can be successful even if not all data was sent + if (errno == 1) { // An undefined value may be read from 'errno' + return 0; + } + } + return 1; + } + +The checker :ref:`unix-StdCLibraryFunctions` must be turned on to get the +warnings from this checker. The supported functions are the same as by ---------------- balazske wrote:
The dependency is only to have modeling checkers that are dependencies of other (non-modeling) checkers. Weak dependency is to have a fixed order of the checkers. Only a new type of dependency could work for this case. (The problem is that `StdCLibraryFunctionsChecker` is both a modeling and non-modeling checker. The situation can be improved only with bigger changes.) https://github.com/llvm/llvm-project/pull/69469 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits