Commit 741d63c2 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

check for empty target image

parent 1d7bb7bf
...@@ -106,6 +106,11 @@ def main(argv): ...@@ -106,6 +106,11 @@ def main(argv):
logger.warning("Wrong API usage") logger.warning("Wrong API usage")
sys.exit(errno.EINVAL) sys.exit(errno.EINVAL)
# Check file size
if os.path.getsize(imagepath) == 0:
logger.error("Invalid file size")
sys.exit(errno.EINVAL)
# Just basic checking for Intel HEX files --- # Just basic checking for Intel HEX files ---
if "hex" in os.path.splitext(imagepath)[1].lower() or flocklab.is_hex_file(imagepath) == True: if "hex" in os.path.splitext(imagepath)[1].lower() or flocklab.is_hex_file(imagepath) == True:
logger.debug("Hex file detected.") logger.debug("Hex file detected.")
......
...@@ -454,9 +454,14 @@ def main(argv): ...@@ -454,9 +454,14 @@ def main(argv):
obsiddict[obsid][core] = platform obsiddict[obsid][core] = platform
# Get the image and save it to a temporary file: # Get the image and save it to a temporary file:
image = imageconf[0].xpath('d:data', namespaces=ns)[0].text image = imageconf[0].xpath('d:data', namespaces=ns)[0].text
# For target platform DPP2LoRa, the <data> tag may be empty if len(image.strip()) == 0:
if len(image.strip()) == 0 and (platform.lower() == "dpp2lora" or platform.lower() == "dpp2lorahg"): # For target platform DPP2LoRa, the <data> tag may be empty (such that the user only has to provide an image for either dpp2lora or dpp2lorahg when using both targets in one test)
continue # skip image validation if (platform.lower() == "dpp2lora" or platform.lower() == "dpp2lorahg"):
continue # skip image validation
if not quiet:
print(("Line %d: element data is empty." % line))
errcnt = errcnt + 1
break
image_line = imageconf[0].xpath('d:data', namespaces=ns)[0].sourceline image_line = imageconf[0].xpath('d:data', namespaces=ns)[0].sourceline
(fd, imagefilename) = tempfile.mkstemp() (fd, imagefilename) = tempfile.mkstemp()
imagefile = os.fdopen(fd, 'w+b') imagefile = os.fdopen(fd, 'w+b')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment