From: Wolfgang Denk Date: Fri, 29 Oct 2010 22:54:04 +0200 Subject: [U-Boot] [PATCH] UBIFS: Change ubifsload to not read beyond the requested size In-Reply-To: <1288343093-31276-1-git-send-email-sr@denx.de> References: <1288343093-31276-1-git-send-email-sr@denx.de> Message-ID: <20101029205404.71F62BB0AD@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Stefan Roese, In message <1288343093-31276-1-git-send-email-sr@denx.de> you wrote: > Until now ubifsload pads the destination with 0 up to a multiple of > UBIFS_BLOCK_SIZE (4KiB) while reading a file to memory. This patch > changes this behaviour to only read to the requested length. This > is either the file length or the length/size provided as parameter > to the ubifsload command. > > Signed-off-by: Stefan Roese > --- > This patch makes the patch [UBIFS: Add padded size to ubifsload output] > posted yesterday obsolete since we're not padding any more now. ... > + /* > + * We need to buffer the data locally for the > + * last block. This is to not pad the destination > + * area to a multiple of UBIFS_BLOCK_SIZE. > + */ > + buff = malloc(UBIFS_BLOCK_SIZE); > + > + /* Read block-siez into temp buffer */ > + ret = read_block(inode, buff, block, dn); > + if (last_block_size) > + dlen = last_block_size; > + else > + dlen = le32_to_cpu(dn->size); How about some error handling? malloc() can fail, and read_block() can fail as well. > + /* Now copy required size back to dest */ > + memcpy(addr, buff, dlen); > + > + free(buff); > + } else { > + ret = read_block(inode, addr, block, dn); > + if (ret) { > + err = ret; > + if (err != -ENOENT) > + break; or simpler: ret = read_block(inode, addr, block, dn); if (ret != -ENOENT) { err = ret; break; } Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "I used to think that the brain was the most wonderful organ in my body. Then I realized who was telling me this." - Emo Phillips