Skip to content

Commit

Permalink
fix the bug of decryptFile on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyi9982 committed Dec 19, 2018
1 parent 6695026 commit 3ec6e4e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/downloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ GENARO_API char *genaro_decrypt_file(genaro_env_t *env,
ctr_crypt(&ctx, (nettle_cipher_func *)aes256_encrypt,
AES_BLOCK_SIZE, ctr, len,
(uint8_t *)file_data + bytes_decrypted,
(const uint8_t *)file_data + bytes_decrypted);
(uint8_t *)file_data + bytes_decrypted);

bytes_decrypted += len;
}
Expand Down
2 changes: 1 addition & 1 deletion src/uploader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ static void verify_file_name_callback(uv_work_t *work_req, int status)
state->log->error(state->env->log_options, state->handle,
"Request failed with status code: %i", req->status_code);

if (state->file_verify_count == GENARO_MAX_VERIFY_BUCKET_ID) {
if (state->file_verify_count == GENARO_MAX_VERIFY_FILE_NAME) {
state->error_status = GENARO_BRIDGE_REQUEST_ERROR;
state->file_verify_count = 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/uploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define GENARO_MAX_CREATE_ENCRYPTED_FILE 3
#define GENARO_MAX_REQUEST_FRAME_ID 3
#define GENARO_MAX_VERIFY_BUCKET_ID 3
#define GENARO_MAX_VERIFY_FILE_NAME 3

typedef enum {
CANCELED = 0,
Expand Down
8 changes: 6 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ int map_file(int fd, uint64_t filesize, uint8_t **map, bool read_only)
size_t read_file(const char *file_path, char **buffer)
{
FILE *fp;
fp = fopen(file_path, "r");
fp = fopen(file_path, "rb");
if (fp == NULL) {
return 0;
}
Expand All @@ -368,17 +368,21 @@ size_t read_file(const char *file_path, char **buffer)
}

size_t read_blocks = 0;
size_t read_bytes = 0;
while ((!feof(fp)) && (!ferror(fp))) {
read_blocks = fread(*buffer + read_blocks, 1, fsize, fp);

if (read_blocks <= 0) {
break;
}

read_bytes += read_blocks;
}

int error = ferror(fp);
fclose(fp);

if (error) {
if (error || (read_bytes != fsize)) {
free(*buffer);
return 0;
}
Expand Down

0 comments on commit 3ec6e4e

Please sign in to comment.