1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-12-26 15:10:40 +05:30

post-merge fixes

This commit is contained in:
Intel A80486DX2-66 2024-11-22 18:33:55 +03:00
parent 87fa559371
commit 098644abe5
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -36,13 +36,12 @@ static bool is_line_ending(byte c) {
void corrupt_byte(Interoperation_Input_Vars) {
uint8_t config = param->config;
FSEEK_MACRO(file, i, SEEK_SET);
byte byte_value = buffer[i];
if (READ_CONFIG(C_PRINTABLE) && !isprint(byte_value))
return INTEROPERATION_SUCCESS;
return;
else if (READ_CONFIG(C_LINE_ENDINGS) && is_line_ending(byte_value))
return INTEROPERATION_SUCCESS;
return;
// generate bit mask
byte threshold = param->threshold,
@ -69,8 +68,6 @@ void corrupt_byte(Interoperation_Input_Vars) {
result->damaged_bytes++;
}
return INTEROPERATION_SUCCESS;
}
Corrupter_Result corrupt_file(Corrupter_Param* param) {
@ -135,10 +132,12 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) {
rewind(file);
// allocate memory for the file content
uint8_t* buffer = malloc(end);
byte* buffer = malloc(end);
if (buffer == NULL) {
result->error = true;
PERROR_MACRO("malloc");
result.error = true;
return result;
}
@ -146,16 +145,12 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) {
if (fread(buffer, 1, end, file) != (size_t) end) {
free(buffer);
if (feof(file)) {
if (feof(file))
ERROR_MSG("fread", "End of file reached");
else
PERROR_MACRO("fread");
fclose(file);
free(result);
exit(EXIT_FAILURE);
}
fclose(file);
result->error = true;
result.error = true;
return result;
}
@ -175,12 +170,25 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) {
// iterate over the file contents
for (file_offset_t i = start; i < end; i++)
CORRUPT_BYTE_MACRO;
}
puts(" [OK]");
// write the buffer to the file
rewind(file);
if (fwrite(buffer, 1, end, file) != (size_t) end) {
free(buffer);
if (feof(file))
ERROR_MSG("fwrite", "End of file reached");
else
PERROR_MACRO("fwrite");
result.error = true;
return result;
}
free(buffer);
result->error = false;
result.error = false;
return result;
}