Move from memmove to memmove_s.
Change-Id: I791029d82c2ed6d3d9f23eada87730ae037c9b6c
diff --git a/src/fdt.c b/src/fdt.c
index f02864a..de54189 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -400,6 +400,8 @@
/* TODO: Clean this up. */
uint8_t *begin = (uint8_t *)hdr + be32toh(hdr->off_mem_rsvmap);
struct fdt_reserve_entry *e = (struct fdt_reserve_entry *)begin;
+ size_t old_size =
+ be32toh(hdr->totalsize) - be32toh(hdr->off_mem_rsvmap);
hdr->totalsize = htobe32(be32toh(hdr->totalsize) +
sizeof(struct fdt_reserve_entry));
@@ -407,8 +409,8 @@
sizeof(struct fdt_reserve_entry));
hdr->off_dt_strings = htobe32(be32toh(hdr->off_dt_strings) +
sizeof(struct fdt_reserve_entry));
- memmove(begin + sizeof(struct fdt_reserve_entry), begin,
- be32toh(hdr->totalsize) - be32toh(hdr->off_mem_rsvmap));
+ memmove_s(begin + sizeof(struct fdt_reserve_entry), old_size, begin,
+ old_size);
e->address = htobe64(addr);
e->size = htobe64(len);
}
diff --git a/src/std.c b/src/std.c
index b7ea2ce..fd52a0f 100644
--- a/src/std.c
+++ b/src/std.c
@@ -21,6 +21,7 @@
/* Declare unsafe functions locally so they are not available globally. */
void *memset(void *s, int c, size_t n);
void *memcpy(void *dst, const void *src, size_t n);
+void *memmove(void *dst, const void *src, size_t n);
void memset_s(void *dest, rsize_t destsz, int ch, rsize_t count)
{
@@ -78,3 +79,24 @@
fail:
panic("memcpy_s failure");
}
+
+void memmove_s(void *dest, rsize_t destsz, const void *src, rsize_t count)
+{
+ if (dest == NULL || src == NULL) {
+ goto fail;
+ }
+
+ if (destsz > RSIZE_MAX || count > RSIZE_MAX) {
+ goto fail;
+ }
+
+ if (count > destsz) {
+ goto fail;
+ }
+
+ memmove(dest, src, count);
+ return;
+
+fail:
+ panic("memmove_s failure");
+}