diff options
author | Elliott Hughes <enh@google.com> | 2018-01-18 16:08:24 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2018-01-18 16:50:14 -0800 |
commit | aaa3b6bbf2e8bf5949a3b9af27c0a458fe62828d (patch) | |
tree | 596501c8946ddc1f245a57089569148b8d1f34ce /fastboot/bootimg_utils.cpp | |
parent | a1e27d342e05fc504ce7140463d17336c53a1af8 (diff) |
Fix fastboot memory corruption.
Bug: http://b/68664649
Test: echo 'ANDROID!' > fake.img ; fastboot -c `python -c "print 'A'*4000"` boot fake.img
Change-Id: I3299e0fba24a6c1f6178c994731a94cea68f7254
Diffstat (limited to 'fastboot/bootimg_utils.cpp')
-rw-r--r-- | fastboot/bootimg_utils.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/fastboot/bootimg_utils.cpp b/fastboot/bootimg_utils.cpp index c1028ef3c..62a26b30a 100644 --- a/fastboot/bootimg_utils.cpp +++ b/fastboot/bootimg_utils.cpp @@ -28,13 +28,15 @@ #include "bootimg_utils.h" +#include "fastboot.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> -void bootimg_set_cmdline(boot_img_hdr* h, const char* cmdline) -{ - strcpy((char*) h->cmdline, cmdline); +void bootimg_set_cmdline(boot_img_hdr* h, const char* cmdline) { + if (strlen(cmdline) >= sizeof(h->cmdline)) die("command line too large: %zu", strlen(cmdline)); + strcpy(reinterpret_cast<char*>(h->cmdline), cmdline); } boot_img_hdr* mkbootimg(void* kernel, int64_t kernel_size, off_t kernel_offset, |