mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-06-09 23:36:03 +09:00
fit_image: Use calloc() to fix reproducibility issue
Vagrant Cascadian reported that mx6cuboxi target no longer builds reproducibility on Debian. One example of builds mismatches: 00096680: 696e 6700 736f 756e 642d 6461 6900 6465 ing.sound-dai.de -00096690: 7465 6374 2d67 7069 6f73 0000 tect-gpios.. +00096690: 7465 6374 2d67 7069 6f73 0061 tect-gpios.a This problem happens because all the buffers in fit_image.c are allocated via malloc(), which does not zero out the allocated buffer. Using calloc() fixes this unpredictable behaviour as it guarantees that the allocated buffer are zero initialized. Reported-by: Vagrant Cascadian <vagrant@reproducible-builds.org> Suggested-by: Tom Rini <trini@konsulko.com> Signed-off-by: Fabio Estevam <festevam@gmail.com> Tested-by: Vagrant Cascadian <vagrant@reproducible-builds.org>
This commit is contained in:
parent
dfd2390dff
commit
aaa91a4e4b
|
@ -388,7 +388,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
|
||||||
size = fit_calc_size(params);
|
size = fit_calc_size(params);
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
return -1;
|
return -1;
|
||||||
buf = malloc(size);
|
buf = calloc(1, size);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
fprintf(stderr, "%s: Out of memory (%d bytes)\n",
|
fprintf(stderr, "%s: Out of memory (%d bytes)\n",
|
||||||
params->cmdname, size);
|
params->cmdname, size);
|
||||||
|
@ -467,7 +467,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
|
||||||
* Allocate space to hold the image data we will extract,
|
* Allocate space to hold the image data we will extract,
|
||||||
* extral space allocate for image alignment to prevent overflow.
|
* extral space allocate for image alignment to prevent overflow.
|
||||||
*/
|
*/
|
||||||
buf = malloc(fit_size + (align_size * image_number));
|
buf = calloc(1, fit_size + (align_size * image_number));
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err_munmap;
|
goto err_munmap;
|
||||||
|
@ -572,7 +572,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
|
||||||
|
|
||||||
/* Allocate space to hold the new FIT */
|
/* Allocate space to hold the new FIT */
|
||||||
size = sbuf.st_size + 16384;
|
size = sbuf.st_size + 16384;
|
||||||
fdt = malloc(size);
|
fdt = calloc(1, size);
|
||||||
if (!fdt) {
|
if (!fdt) {
|
||||||
fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
|
fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
|
||||||
__func__, size);
|
__func__, size);
|
||||||
|
@ -673,7 +673,7 @@ static int copyfile(const char *src, const char *dst)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(512);
|
buf = calloc(1, 512);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
printf("Can't allocate buffer to copy file\n");
|
printf("Can't allocate buffer to copy file\n");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user