Skip to content

Commit

Permalink
Fix bug where a symbolic link file ended shredding prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
ADBeveridge committed May 3, 2024
1 parent 42d02ef commit 268c229
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/corrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ G_DEFINE_TYPE(RaiderCorrupt, raider_corrupt, G_TYPE_OBJECT)

static void list_files(const char *directory, GPtrArray* files);
uint8_t corrupt_file(RaiderCorrupt* corrupt);
uint8_t corrupt_folder(RaiderCorrupt* corrupt);
int corrupt_folder(RaiderCorrupt* corrupt);
uint8_t corrupt_unlink_file(const char *filename);
uint8_t corrupt_unlink_folder(const char *filename);
off_t corrupt_check_file(const char *filename);
Expand Down Expand Up @@ -117,18 +117,17 @@ static void list_files(const char *directory, GPtrArray* files) {
}
}

uint8_t corrupt_folder(RaiderCorrupt* corrupt)
int corrupt_folder(RaiderCorrupt* corrupt)
{
char* folder = g_file_get_path(corrupt->file);
GPtrArray* files = g_ptr_array_new();
uint8_t ret = 0;
int ret = 0;

list_files(folder, files);

for (guint i = 0; i < files->len; i++)
for (int i = 0; i < files->len; i++)
{
char* filename = g_ptr_array_index (files, i);

int steps_num = sizeof(steps) / sizeof(steps[0]);

corrupt->progress = (double)i/(double)files->len;
Expand All @@ -138,21 +137,21 @@ uint8_t corrupt_folder(RaiderCorrupt* corrupt)
// Shred the file by overwriting it many times.
off_t filesize = corrupt_check_file(filename);
if (filesize == -1)
{
ret = -1;
continue;
}

uint8_t i;
for (i = 0; i < steps_num; i++)
for (int i = 0; i < steps_num; i++)
{
if (corrupt_step(corrupt->task, filename, filesize, steps[i], i) != 0)
{
ret = 1;
ret = -1;
fprintf(stderr, "corrupt: failed to perform shredding step\n");
break;
}
}

if (ret == -1)
break;

corrupt_unlink_file(filename);
}

Expand Down Expand Up @@ -182,7 +181,8 @@ uint8_t corrupt_file(RaiderCorrupt* corrupt)
{
if (corrupt_step(corrupt->task, filename, filesize, steps[i], i) != 0)
{
ret = 1;
ret = -1;
fprintf(stderr, "corrupt: failed to perform shredding step\n");
break;
}

Expand Down Expand Up @@ -229,7 +229,7 @@ off_t corrupt_check_file(const char *filename)
// Run some checks on the file.
if(lstat(filename, &st) != 0)
{
fprintf(stderr, "corrupt: current file not found (%s)\n", filename);
fprintf(stderr, "corrupt: current file not found\n");
return -1;
}
if (S_ISLNK(st.st_mode) == 1)
Expand Down

0 comments on commit 268c229

Please sign in to comment.