Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-47203

LOGV2 macros should protect against forgetting trailing commas to separate arguments

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: Logging
    • None
    • Server Security
    • Fully Compatible

      One of the most common mistakes observed during the code reviews for updating the sharding log lines based on the LOGV2 style guide (see SERVER-46799) was omitting a trailing comma to separate the format string from the message string, or to separate the message string from the first attribute name. There were 30 instances of this mistake made across the 10 individuals (myself included) who worked on those changes.

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
      index 960d189008..04a7937b2d 100644
      --- a/src/mongo/s/server.cpp
      +++ b/src/mongo/s/server.cpp
      @@ -651,7 +651,7 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
           if (!status.isOK()) {
               LOGV2_ERROR(22858,
                           "Error initializing authorization data: {error}",
      -                    "Error initializing authorization data"
      +                    "Error initializing authorization data",
                           "error"_attr = status);
               return EXIT_SHARDING_ERROR;
           }
      

      This likely occurred due to the way in which engineers went about copy-pasting from the format string to create a sensible message string. It'd be great if the LOGV2 macros could protect against this, although perhaps unnecessary if we aren't going to require format strings in addition to message strings for new log messages. My idea for an approach would be to have the format and message strings be distinct nominal types and to have user-defined suffixes for creating the appropriate type. The compiler would error if two string literals with different ud-suffixes were attempted to be concatenated.

            Assignee:
            backlog-server-security [DO NOT USE] Backlog - Security Team
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: