base/logging: Prevent test-only crash caused by std::string(nullptr)

If logging is not set up properly, ~ScopedLoggingSettings() can make a
call to InitLogging() that constructs a std::string from nullptr. This
undefined behavior would occur when BaseInitLoggingImpl() sets the value
of `*g_log_file_name`.

This can occur in at least one scenario: when the logging destination is
LOG_TO_FILE, but no log file is set.

I think this caused a crash in sql_recovery_lpm_fuzzer on Windows (see
linked bug). However, a little more UB may also have been involved
because the fuzzer does not call InitLogging().

To prevent this undefined behavior from occuring, this CL makes the
following changes:

* It changes the type of LoggingSettings::log_file_path from a pointer
  to a string type to prevent nullptr-related accidents in the future.

* It changes ScopedLoggingSettings::log_file_name_ from a
  std::unique_ptr<> of a string type to just a plain string type.

* It upgrades some DCHECKs to CHECKs in BaseInitLoggingImpl(). Note that
  the old `DCHECK(settings.log_file_path)` would have been sufficient to
  prevent the UB in question, but we observed the crash in a fuzzer
  where DCHECKs were not enabled.

Bug: 331909454
Change-Id: I27abdb3eac6fec82853a7643643b2dacd7f7571c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5416213
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1287534}
NOKEYCHECK=True
GitOrigin-RevId: b4b65e3b7219a0150106e6798d7d75b401aec1d0
1 file changed