summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Maier <brandon.maier@collins.com>2022-11-02 17:47:52 -0500
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-07 08:24:33 +0100
commita28c5307d6c32a819521542903e678c3c544fa6c (patch)
treedd4ddecebd83536df73153601d97dfdb5b30eddb
parentccff5611fb1da96bc4aa805bc9a2f92ae6ce2255 (diff)
misc-utils: flashcp: check for lseek errors
Add a safe_lseek wrapper to check for lseek errors. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--misc-utils/flashcp.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c
index 061eea1..89d3386 100644
--- a/misc-utils/flashcp.c
+++ b/misc-utils/flashcp.c
@@ -170,13 +170,23 @@ static void safe_write (int fd,const void *buf,size_t count,size_t written,unsig
}
}
-static void safe_rewind (int fd,const char *filename)
+static off_t safe_lseek (int fd,off_t offset,int whence,const char *filename)
{
- if (lseek (fd,0L,SEEK_SET) < 0)
+ off_t off;
+
+ off = lseek (fd,offset,whence);
+ if (off < 0)
{
- log_printf (LOG_ERROR,"While seeking to start of %s: %m\n",filename);
+ log_printf (LOG_ERROR,"While seeking on %s: %m\n",filename);
exit (EXIT_FAILURE);
}
+
+ return off;
+}
+
+static void safe_rewind (int fd,const char *filename)
+{
+ safe_lseek(fd,0L,SEEK_SET,filename);
}
/******************************************************************************/
@@ -455,7 +465,7 @@ DIFF_BLOCKS:
safe_read (fil_fd,filename,src,i,flags & FLAG_VERBOSE);
/* read from device */
- current_dev_block = lseek(dev_fd, 0, SEEK_CUR);
+ current_dev_block = safe_lseek(dev_fd, 0, SEEK_CUR, device);
safe_read (dev_fd,device,dest,i,flags & FLAG_VERBOSE);
/* compare buffers, if not the same, erase and write the block */
@@ -463,7 +473,7 @@ DIFF_BLOCKS:
{
diffBlock++;
/* erase block */
- lseek(dev_fd, current_dev_block, SEEK_SET);
+ safe_lseek(dev_fd, current_dev_block, SEEK_SET, device);
if (ioctl (dev_fd,MEMERASE,&erase) < 0)
{
log_printf (LOG_NORMAL,"\n");
@@ -474,7 +484,7 @@ DIFF_BLOCKS:
}
/* write to device */
- lseek(dev_fd, current_dev_block, SEEK_SET);
+ safe_lseek(dev_fd, current_dev_block, SEEK_SET, device);
safe_write(dev_fd,src,i,written,(unsigned long long)filestat.st_size,device,flags & FLAG_VERBOSE);
}