sagarpant1 / protobuf

Other
0 stars 1 forks source link

Potential issue in src/google/protobuf/compiler/cpp/cpp_file.cc: Unchecked return from initialization function #2

Open monocle-ai opened 3 years ago

monocle-ai commented 3 years ago

What is a Conditionally Uninitialized Variable? The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in undefined behavior.

4 instances of this defect were found in the following locations:


Instance 1 File : src/google/protobuf/compiler/cpp/cpp_file.cc Enclosing Function : GeneratePBHeader@FileGenerator@cpp@compiler@protobuf@google Function : GetBootstrapBasename@cpp@compiler@protobuf@google https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_file.cc#L292 Issue in: _targetbasename

Code extract:

  if (options_.proto_h) {
    std::string target_basename = StripProto(file_->name());
    if (!options_.opensource_runtime) {
      GetBootstrapBasename(options_, target_basename, &target_basename); <------ HERE
    }
    format("#include \"$1$.proto.h\"  // IWYU pragma: export\n",

How can I fix it? Correct reference usage found in src/google/protobuf/compiler/cpp/cpp_helpers.cc at line 1295. https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_helpers.cc#L1295 Code extract:

bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
                    bool bootstrap_flag, std::string* basename) {
  std::string bootstrap_basename;
  if (!GetBootstrapBasename(options, *basename, &bootstrap_basename)) { <------ HERE
    return false;
  }

Instance 2 File : src/google/protobuf/compiler/cpp/cpp_file.cc Enclosing Function : GenerateSourceIncludes@FileGenerator@cpp@compiler@protobuf@google Function : GetBootstrapBasename@cpp@compiler@protobuf@google https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_file.cc#L386 Issue in: _targetbasename

Code extract:

  Formatter format(printer, variables_);
  std::string target_basename = StripProto(file_->name());
  if (!options_.opensource_runtime) {
    GetBootstrapBasename(options_, target_basename, &target_basename); <------ HERE
  }
  target_basename += options_.proto_h ? ".proto.h" : ".pb.h";

How can I fix it? Correct reference usage found in src/google/protobuf/compiler/cpp/cpp_helpers.cc at line 1295. https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_helpers.cc#L1295 Code extract:

bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
                    bool bootstrap_flag, std::string* basename) {
  std::string bootstrap_basename;
  if (!GetBootstrapBasename(options, *basename, &bootstrap_basename)) { <------ HERE
    return false;
  }

Instance 3 File : src/google/protobuf/compiler/cpp/cpp_file.cc Enclosing Function : GenerateSourceIncludes@FileGenerator@cpp@compiler@protobuf@google Function : GetBootstrapBasename@cpp@compiler@protobuf@google https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_file.cc#L424 Issue in: basename

Code extract:

      if (!options_.opensource_runtime && IsDepWeak(dep)) continue;
      std::string basename = StripProto(dep->name());
      if (IsBootstrapProto(options_, file_)) {
        GetBootstrapBasename(options_, basename, &basename); <------ HERE
      }
      format("#include \"$1$.proto.h\"\n", basename);

How can I fix it? Correct reference usage found in src/google/protobuf/compiler/cpp/cpp_helpers.cc at line 1295. https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_helpers.cc#L1295 Code extract:

bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
                    bool bootstrap_flag, std::string* basename) {
  std::string bootstrap_basename;
  if (!GetBootstrapBasename(options, *basename, &bootstrap_basename)) { <------ HERE
    return false;
  }

Instance 4 File : src/google/protobuf/compiler/cpp/cpp_file.cc Enclosing Function : GenerateDependencyIncludes@FileGenerator@cpp@compiler@protobuf@google Function : GetBootstrapBasename@cpp@compiler@protobuf@google https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_file.cc#L1383 Issue in: basename

Code extract:

    if (IsDepWeak(file_->dependency(i))) continue;

    if (IsBootstrapProto(options_, file_)) {
      GetBootstrapBasename(options_, basename, &basename); <------ HERE
    }

How can I fix it? Correct reference usage found in src/google/protobuf/compiler/cpp/cpp_helpers.cc at line 1295. https://github.com/sagarpant1/protobuf/blob/6b1d0f11493ef2317ea74aa00804835a10ebaf19/src/google/protobuf/compiler/cpp/cpp_helpers.cc#L1295 Code extract:

bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
                    bool bootstrap_flag, std::string* basename) {
  std::string bootstrap_basename;
  if (!GetBootstrapBasename(options, *basename, &bootstrap_basename)) { <------ HERE
    return false;
  }
siva-msft commented 3 years ago

lgtm - have already reached out, i suppose