diff options
author | Michael T Farnworth <michael@turf.org> | 2020-02-22 14:20:49 +0000 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2020-03-29 18:47:32 +0200 |
commit | 96092a8eeadde1b868fb9b3345b361ed4e70c84d (patch) | |
tree | c7e52e260d8541e42055890d8b185d68a5adc738 /tools | |
parent | bf5ea2a8dc8397f7b0dd975c06f9fc5dd04cb91b (diff) | |
download | upstream-96092a8eeadde1b868fb9b3345b361ed4e70c84d.tar.gz upstream-96092a8eeadde1b868fb9b3345b361ed4e70c84d.tar.bz2 upstream-96092a8eeadde1b868fb9b3345b361ed4e70c84d.zip |
mkrasimage: fix segmentation fault
Code was attempting to determine the size of the file
before it was actually known and allocating insufficient
memory space. Images above a certain size caused a
segmentation fault. Moving the calloc() ensured ensured
that large images didn't result in a buffer overflow on
memcpy().
Signed-off-by: Michael T Farnworth <michael@turf.org>
[fixed name in From to match one in SoB]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
(cherry picked from commit b468353a373d181c4362ff690d7b22a08f5f6949)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/firmware-utils/src/mkrasimage.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tools/firmware-utils/src/mkrasimage.c b/tools/firmware-utils/src/mkrasimage.c index 8eee29cc08..8d830ead79 100644 --- a/tools/firmware-utils/src/mkrasimage.c +++ b/tools/firmware-utils/src/mkrasimage.c @@ -315,6 +315,16 @@ int build_image() map_file(&kernel); map_file(&rootfs); + /* As ZyXEL Web-GUI only accept images with a rootfs equal or larger than the first firmware shipped + * for the device, we need to pad rootfs partition to this size. To perform further calculations, we + * decide the size of this part here. In case the rootfs we want to integrate in our image is larger, + * take it's size, otherwise the supplied size. + * + * Be careful! We rely on assertion of correct size to be performed beforehand. It is unknown if images + * with a to large rootfs are accepted or not. + */ + rootfs_out.size = rootfs_size < rootfs.size ? rootfs.size : rootfs_size; + /* * Allocate memory and copy input rootfs for temporary output rootfs. * This is important as we have to generate the rootfs checksum over the @@ -446,14 +456,5 @@ int main(int argc, char *argv[]) if (ret) usage(EXIT_FAILURE); - /* As ZyXEL Web-GUI only accept images with a rootfs equal or larger than the first firmware shipped - * for the device, we need to pad rootfs partition to this size. To perform further calculations, we - * decide the size of this part here. In case the rootfs we want to integrate in our image is larger, - * take it's size, otherwise the supplied size. - * - * Be careful! We rely on assertion of correct size to be performed beforehand. It is unknown if images - * with a to large rootfs are accepted or not. - */ - rootfs_out.size = rootfs_size < rootfs.size ? rootfs.size : rootfs_size; return build_image(); } |