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

The edit() function (command) in shell/dbShell.cpp could index off the end of a string

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.1.0
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Environment:
      Any
    • ALL

      The code in the new 'edit' command in the shell uses the .data() member of <basic_string> (i.e. <string>) but then tests for NUL to end the string. The code should use .c_str() instead, which does NUL terminate. This is probably not a real-world error because real implementations of <string> seem to store strings NUL-terminated anyway.

      #ifndef _WIN32
      static void edit(const string& var){
      static const char * editor = getenv("EDITOR");
      if (!editor)

      { cout << "please define the EDITOR environment variable" << endl; return; }

      for (const char* p=var.data(); *p ; p++){ // should use c_str() instead of data()
      if (! (isalnum(*p) || *p == '_' || *p == '.'))

      { cout << "can only edit variable or property" << endl; return; }

      }

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: