Use bounded string functions.
The bounds add a bit of safety in avoiding memory bugs and there are
sensible bounds in the cases we have been using them.
Change-Id: I381e122f356a54e5c0f1e183e521169522bc8aa9
diff --git a/src/cpio.c b/src/cpio.c
index 58626ec..6cf8757 100644
--- a/src/cpio.c
+++ b/src/cpio.c
@@ -44,6 +44,7 @@
static bool cpio_next(struct memiter *iter, const char **name,
const void **contents, size_t *size)
{
+ static const char trailer[] = "TRAILER!!!";
size_t len;
struct memiter lit = *iter;
const struct cpio_header *h = (const struct cpio_header *)lit.next;
@@ -71,7 +72,7 @@
/* TODO: Check that string is null-terminated. */
/* Stop enumerating files when we hit the end marker. */
- if (!strcmp(*name, "TRAILER!!!")) {
+ if (!strncmp(*name, trailer, sizeof(trailer))) {
return false;
}
@@ -94,7 +95,7 @@
struct memiter iter = *cpio;
while (cpio_next(&iter, &fname, &fcontents, &fsize)) {
- if (!strcmp(fname, string_data(name))) {
+ if (!strncmp(fname, string_data(name), STRING_MAX_SIZE)) {
memiter_init(it, fcontents, fsize);
return true;
}