pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
308 stars 110 forks source link

Forgetting to specify lebsize causes div-by-zero crash in ubifs build #68

Closed thirtythreeforty closed 5 years ago

thirtythreeforty commented 5 years ago

I mistakenly specified my flash without a lebsize:

flash w25q64 {
    pebsize = 4096
    numpebs = 2048
    minimum-io-unit-size = 1
    sub-page-size = 1
    vid-header-offset = 64
}

and tried to build an ubifs image using this definition. I get a crash:

support/scripts/genimage.sh: line 40:  6959 Floating point exception(core dumped) genimage --rootpath "${TARGET_DIR}" --tmppath "${GENIMAGE_TMP}" --inputpath "${BINARIES_DIR}" --outputpath "${BINARIES_DIR}" --config "${GENIMAGE_CFG}"

Analyzing the coredump suggests a div-by-zero problem:

Program terminated with signal SIGFPE, Arithmetic exception.
#0  0x000055f0b21195f2 in ubifs_generate (image=0x55f0b2ab4b30) at image-ubifs.c:33
33          max_leb_cnt = max_size / image->flash_type->lebsize;
(gdb) bt
#0  0x000055f0b21195f2 in ubifs_generate (image=0x55f0b2ab4b30) at image-ubifs.c:33
#1  0x000055f0b2110bb4 in image_generate (image=0x55f0b2ab4b30) at genimage.c:233
#2  0x000055f0b2110a9e in image_generate (image=0x55f0b2ab4c50) at genimage.c:219
#3  0x000055f0b2110a9e in image_generate (image=0x55f0b2ab46d0) at genimage.c:219
#4  0x000055f0b211235f in main (argc=11, argv=0x7fffccf1d1e8) at genimage.c:749

Probably, genimage should check that lebsize is specified if ubifs is expecting to use it (and give an error if not).

For what it's worth, a plain ubi image worked fine without lebsize.

michaelolbrich commented 5 years ago

Right, the image-ubifs code should check this. Probably some sanity check for all flash values in the ubi / ubifs code.