Skip to content

Mis-used string pointers in opendkim.c and vbr.c #244

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jcastle-gh
Copy link

Enhanced warnings in Debian and Fedora build logs expose some string addressing problems in vbr.c and opendkim.c.

  1. In https://bugs.debian.org/1075339 which is about a different problem, the build log attached to the bug shows a warning from -DFORTIFY_SOURCE:
vbr.c: In function 'vbr_query' vbr.c:1069:43: warning: "unable to start resolver for.." directive output truncated writing 30 bytes into a region of size 8 [-Wformat-truncation=]
1069 |                                  "unable to start resolver for '%s'",
     |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
vbr.c:1081:43: warning: "unable to start query for '" directive output truncated writing 27 bytes into a region of size 8 [-Wformat-truncation=]
1081 |                                  "unable to start query for '%s'",
     |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~

In two snprintf() calls the size of the buffer pointer is mistakenly used instead of the size of the buffer itself, resulting in a truncated error message. There is already a static function vbr_error() which can safely replace snprintf here.

  1. Browsing the Fedora build log for similar issues shows one in opendkim.c.
    https://kojipkgs.fedoraproject.org//packages/opendkim/2.11.0/0.42.fc43/data/logs/x86_64/build.log
opendkim.c: In function 'dkimf_add_signrequest':
opendkim.c:5023:38: warning: the comparison will always evaluate as 'false' for the address of 'mctx_domain' will never be NULL [-Waddress]
5023 |                     dfc->mctx_domain == NULL)
     |                                      ^~
opendkim.c:523:25: note: 'mctx_domain' declared here
523 |         unsigned char   mctx_domain[DKIM_MAXHOSTNAMELEN + 1];
    |                         ^~~~~~~~~~~

The code is trying to return an error if mctx_domain is an empty string. 'mctx_domain' is the string buffer itself, not a malloced pointer to it, so the code should be looking for "mctx_domain[0] == '\0'". This bug means later code uses the possibly empty string assuming it's not empty, so it should be fixed even without a failing test case.

Enhanced warnings in Debian and Fedora build logs expose some string
addressing problems in vbr.s and opendkim.c.

1. In https://bugs.debian.org/1075339 which is about a different
   problem, the build log attached to the bug shows a warning from
   -DFORTIFY_SOURCE:
  vbr.c: In function 'vbr_query'
  vbr.c:1069:43: warning: "unable to start resolver for.." directive output truncated writing 30 bytes into a region of size 8 [-Wformat-truncation=]
   1069 |                                  "unable to start resolver for '%s'",
        |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
  vbr.c:1081:43: warning: "unable to start query for '" directive output truncated writing 27 bytes into a region of size 8 [-Wformat-truncation=]
   1081 |                                  "unable to start query for '%s'",
        |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~
The size of the buffer pointer is mistakenly used instead of the size of
the buffer itself, resulting in a truncated error message.

2.Looking at the Fedora build log for similar issues shows one in
opendkim.c.
  https://kojipkgs.fedoraproject.org//packages/opendkim/2.11.0/0.42.fc43/data/logs/x86_64/build.log
  opendkim.c: In function 'dkimf_add_signrequest':
  opendkim.c:5023:38: warning: the comparison will always evaluate as 'false' for the address of 'mctx_domain' will never be NULL [-Waddress]
   5023 |                     dfc->mctx_domain == NULL)
        |                                      ^~
  opendkim.c:523:25: note: 'mctx_domain' declared here
   523 |         unsigned char   mctx_domain[DKIM_MAXHOSTNAMELEN + 1];
       |                         ^~~~~~~~~~~
The code is checking if mctx_domain is an empty string. 'mctx_domain'
is the string buffer itself, not a malloced pointer to it, so the code
should be looking for "mctx_domain[0] == '\0'". Later code uses the
string assuming it's not empty, so it seems a good idea to fix it
regardless.
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.

1 participant