snapshot: md5sum return codes are not properly handled
[project/fstools.git] / libfstools / snapshot.c
index 1ec7b87..4870cf7 100644 (file)
@@ -39,7 +39,7 @@ verify_file_hash(char *file, uint32_t *hash)
 {
        uint32_t md5[4];
 
-       if (md5sum(file, md5)) {
+       if (md5sum(file, md5) <= 0) {
                ULOG_ERR("failed to generate md5 sum\n");
                return -1;
        }
@@ -120,7 +120,7 @@ snapshot_write_file(struct volume *v, int block, char *file, uint32_t seq, uint3
        int in = 0, len, offset;
        int ret = -1;
 
-       if (stat(file, &s) || md5sum(file, md5)) {
+       if (stat(file, &s) || md5sum(file, md5) != s.st_size) {
                ULOG_ERR("stat failed on %s\n", file);
                goto out;
        }
@@ -329,13 +329,19 @@ mount_snapshot(struct volume *v)
        snapshot_sync(v);
        setenv("SNAPSHOT", "magic", 1);
        _ramoverlay("/rom", "/overlay");
-       system("/sbin/snapshot unpack");
+       if (system("/sbin/snapshot unpack") == -1) {
+               perror("system");
+               return -1;
+       }
        foreachdir("/overlay/", handle_whiteout);
        mkdir("/volatile", 0700);
        _ramoverlay("/rom", "/volatile");
        mount_move("/rom/volatile", "/volatile", "");
        mount_move("/rom/rom", "/rom", "");
-       system("/sbin/snapshot config_unpack");
+       if (system("/sbin/snapshot config_unpack")) {
+               perror("system");
+               return -1;
+       }
        foreachdir("/volatile/", handle_whiteout);
        unsetenv("SNAPSHOT");
        return -1;