summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bolte <sbolte@lavabit.com>2013-05-15 16:26:22 +0200
committerStefan Bolte <sbolte@lavabit.com>2013-05-15 16:26:22 +0200
commit79a886123ad7405692b35665f952ec211c90db67 (patch)
tree5fda6eaa3025dbdc03e0b67cae290ce94647e463
parent19ba63435ea39eb865e593b493fef517267b788e (diff)
downloaddwb-79a886123ad7405692b35665f952ec211c90db67.zip
Check for currupted files
-rw-r--r--tools/exar/exar.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/exar/exar.c b/tools/exar/exar.c
index 6824846c..b5773b01 100644
--- a/tools/exar/exar.c
+++ b/tools/exar/exar.c
@@ -40,7 +40,7 @@
#define HDR_END (HDR_SIZE + SZ_SIZE)
#define DIR_FLAG (100)
-#define FILE_FLAG (102);
+#define FILE_FLAG (102)
#define LOG(level, format, ...) do { if (s_verbose & EXAR_VERBOSE_L##level) \
fprintf(stderr, "exar-log%d: "format, level, __VA_ARGS__); } while(0)
@@ -148,6 +148,7 @@ exar_unpack(const char *path, const char *dest)
char name[SZ_NAME], size[SZ_SIZE], flag, rbuf;
size_t fs;
FILE *of, *f = NULL;
+ char *endptr;
unsigned char version[SZ_VERSION] = {0}, orig_version[SZ_VERSION] = {0};
LOG(3, "Opening %s for reading\n", path);
@@ -197,6 +198,12 @@ exar_unpack(const char *path, const char *dest)
break;
if (fread(size, 1, SZ_SIZE, f) != SZ_SIZE)
break;
+ if (flag != DIR_FLAG && flag != FILE_FLAG)
+ {
+ LOG(1, "No file flag found for %s\n", name);
+ fprintf(stderr, "The archive seems to be corrupted%s", "\n");
+ goto error_out;
+ }
if (flag == DIR_FLAG)
{
LOG(1, "Creating directory %s\n", name);
@@ -205,7 +212,15 @@ exar_unpack(const char *path, const char *dest)
else
{
LOG(1, "Unpacking %s\n", name);
- fs = strtoul(size, NULL, 8);
+
+ fs = strtoul(size, &endptr, 8);
+ if (*endptr)
+ {
+ LOG(1, "Cannot determine file size for %s\n", name);
+ fprintf(stderr, "The archive seems to be corrupted%s", "\n");
+ goto error_out;
+ }
+
LOG(3, "Opening %s for writing\n", name);
of = fopen(name, "w");
if (of == NULL)