Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabiszewski committed Apr 23, 2022
1 parent 811bac3 commit 4b60805
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions ChangeLog
@@ -1,3 +1,4 @@
2022-04-23: Fix formatting
2022-04-23: Fix checking boundary of deobfuscation key which could cause buffer over-read with corrupt data
2022-04-23: Fix issue with corrupt data with empty lookup string which could lead to read beyond buffer
2022-04-23: Fix faulty checks for array boundary which caused buffer over-read
Expand Down
22 changes: 11 additions & 11 deletions src/buffer.c
Expand Up @@ -49,15 +49,15 @@ MOBIBuffer * mobi_buffer_init(const size_t len) {
*/
MOBIBuffer * mobi_buffer_init_null(unsigned char *data, const size_t len) {
MOBIBuffer *buf = malloc(sizeof(MOBIBuffer));
if (buf == NULL) {
if (buf == NULL) {
debug_print("%s", "Buffer allocation failed\n");
return NULL;
}
buf->data = data;
buf->offset = 0;
buf->maxlen = len;
buf->offset = 0;
buf->maxlen = len;
buf->error = MOBI_SUCCESS;
return buf;
return buf;
}

/**
Expand Down Expand Up @@ -604,11 +604,11 @@ void mobi_buffer_setpos(MOBIBuffer *buf, const size_t pos) {
@param[in] buf MOBIBuffer structure
*/
void mobi_buffer_free(MOBIBuffer *buf) {
if (buf == NULL) { return; }
if (buf->data != NULL) {
free(buf->data);
}
free(buf);
if (buf == NULL) { return; }
if (buf->data != NULL) {
free(buf->data);
}
free(buf);
}

/**
Expand All @@ -620,6 +620,6 @@ void mobi_buffer_free(MOBIBuffer *buf) {
@param[in] buf MOBIBuffer structure
*/
void mobi_buffer_free_null(MOBIBuffer *buf) {
if (buf == NULL) { return; }
free(buf);
if (buf == NULL) { return; }
free(buf);
}
10 changes: 5 additions & 5 deletions src/index.c
Expand Up @@ -434,11 +434,11 @@ static MOBI_RET mobi_parse_index_entry(MOBIIndx *indx, const MOBIIdxt idxt, cons
i++;
}
indx->entries[entry_number].tags = malloc(tagx->tags_count * sizeof(MOBIIndexTag));
if (indx->entries[entry_number].tags == NULL) {
debug_print("Memory allocation failed (%zu bytes)\n", tagx->tags_count * sizeof(MOBIIndexTag));
free(ptagx);
return MOBI_MALLOC_FAILED;
}
if (indx->entries[entry_number].tags == NULL) {
debug_print("Memory allocation failed (%zu bytes)\n", tagx->tags_count * sizeof(MOBIIndexTag));
free(ptagx);
return MOBI_MALLOC_FAILED;
}
i = 0;
while (i < ptagx_count) {
uint32_t tagvalues_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/memory.c
Expand Up @@ -25,7 +25,7 @@
MOBIData * mobi_init(void) {
MOBIData *m = NULL;
m = calloc(1, sizeof(MOBIData));
if (m == NULL) { return NULL; }
if (m == NULL) { return NULL; }
m->use_kf8 = true;
m->kf8_boundary_offset = MOBI_NOTSET;
m->drm_key = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/opf.c
Expand Up @@ -1174,10 +1174,10 @@ MOBI_RET mobi_build_opf_metadata(OPF *opf, const MOBIData *m, const MOBIRawml *
}
if (rawml->orth->orth_index_name) {
opf->metadata->x_meta->default_lookup_index = calloc(OPF_META_MAX_TAGS, sizeof(char*));
if (opf->metadata->x_meta->default_lookup_index == NULL) {
debug_print("%s\n", "Memory allocation failed");
return MOBI_MALLOC_FAILED;
}
if (opf->metadata->x_meta->default_lookup_index == NULL) {
debug_print("%s\n", "Memory allocation failed");
return MOBI_MALLOC_FAILED;
}
opf->metadata->x_meta->default_lookup_index[0] = strdup(rawml->orth->orth_index_name);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/parse_rawml.c
Expand Up @@ -1976,11 +1976,11 @@ MOBI_RET mobi_strip_mobitags(MOBIPart *part) {
part_size += curr->size;

unsigned char *new_data = malloc(part_size);
if (new_data == NULL) {
mobi_list_del_all(first);
debug_print("%s\n", "Memory allocation failed");
return MOBI_MALLOC_FAILED;
}
if (new_data == NULL) {
mobi_list_del_all(first);
debug_print("%s\n", "Memory allocation failed");
return MOBI_MALLOC_FAILED;
}
unsigned char *data_out = new_data;
while (first) {
memcpy(data_out, first->fragment, first->size);
Expand Down
4 changes: 2 additions & 2 deletions tools/mobimeta.c
Expand Up @@ -276,14 +276,14 @@ int main(int argc, char *argv[]) {
}
char infile[FILENAME_MAX];
strncpy(infile, argv[optind], FILENAME_MAX - 1);
infile[FILENAME_MAX - 1] = '\0';
infile[FILENAME_MAX - 1] = '\0';
normalize_path(infile);

if (file_args >= 2) { optind++; }

char outfile[FILENAME_MAX];
strncpy(outfile, argv[optind], FILENAME_MAX - 1);
outfile[FILENAME_MAX - 1] = '\0';
outfile[FILENAME_MAX - 1] = '\0';
normalize_path(outfile);

/* Initialize MOBIData structure */
Expand Down

0 comments on commit 4b60805

Please sign in to comment.