Uploaded image for project: 'Qpid Dispatch'
  1. Qpid Dispatch
  2. DISPATCH-1009

_qd_policy_link_user_name_subst can return an unterminated string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0.1
    • None
    • Policy Engine
    • None

    Description

      On fedora 28 the gcc 8.1.1 compiler gives this warning-as-error:

      /home/aconway/dispatch/src/policy.c: In function '_qd_policy_link_user_name_subst':
      /home/aconway/dispatch/src/policy.c:541:9: error: 'strncpy' output may be truncated copying between 0 and 8 bytes from a string of length 7 [-Werror=stringop-truncation]
               strncpy(obuf, duser, copysize);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      cc1: all warnings being treated as errors

       

      The error is correct: the function is using strncpy to copy a string into a space that may be too small for it, resulting in an un-terminated string.

      I fixed some similar issues already but I'm confused by what's going on here: it looks like we are searching for the uname parameter and replacing it with "${user}" which seems backwards.

      The function would be simpler and clearer if it used snprintf rather than successive strncpy, i.e.

          n = snprintf(obuf, osize, "%s%s%s", leading, duser, trailing);

      but the problem of properly handling the error if the resulting string is too big for obuf remains.

      Attachments

        Activity

          People

            chug Charles E. Rolke
            aconway Alan Conway
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: