chip/host: Make persistence's path handling more robust
chip/host: Make persistence's path handling more robust

Originally I only touched the file because gcc was complaining that
snprintf might end up creating a non-terminated string even though
the code already care about that.

But there was another failure mode in there: persistence is used to
provide some semi-permanent temporary storage whose naming rules are
robust against multiple invocations of the same executable while also
avoiding collisions between multiple processes trying to create such
files at the same time (such as many parallel test suite runs).
If the executable's path is close to the limit given in PATH_MAX
(no matter if that is the true limit of the OS) filenames would be
truncated silently. Since a single executable can create multiple
such files only differentiated by their "tag", added as a suffix,
we'd end up with a test using the same file for multiple purposes
which is not the kind of issue I'd want to debug.

Instead, define some reasonably-looking limits and bail out explicitly
using ASSERT: If things go south, at least there's a constraint
violation message with a file name and source line to hunt for, like
this:
ASSERTION FAIL: chip/host/persistence.c:55:get_storage_path - sz <= max_len

While at it, also explain the purpose of these routines and why mkstemp
isn't a suitable replacement so the next hapless soul doesn't have
to do the same kind of digging I did.

BUG=b:185477664
BRANCH=none
TEST=New toolchain doesn't fail on chip/host/persistence.c anymore.
The tests still pass. Also tested that the assert triggers properly
by locally changing it to some ridiculously small value and running
the tests.

Signed-off-by: Patrick Georgi <bc411205f21846a74924ee7b489c75617ec76078@google.com>
Change-Id: I4869bb58861220401d58755489e896bbcb2102d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2846333
Reviewed-by: Patrick Georgi <bc411205f21846a74924ee7b489c75617ec76078@chromium.org>
Reviewed-by: Manoj Gupta <1d49d0f302d724a1dc5fc4d717d15418e9808ddd@chromium.org>
Commit-Queue: Patrick Georgi <bc411205f21846a74924ee7b489c75617ec76078@chromium.org>
Tested-by: Patrick Georgi <bc411205f21846a74924ee7b489c75617ec76078@chromium.org>

coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec