Commit 1f1cb7bb authored by npzacs's avatar npzacs
Browse files

Use _read_file() to read MKB

Fix handling of errors when reading MKB.
parent bdd3f429
......@@ -431,18 +431,21 @@ static size_t _read_file(AACS *aacs, const char *file, void **data)
static MKB *_mkb_open(AACS *aacs)
{
AACS_FILE_H *fp;
MKB *mkb;
size_t size;
void *data;
MKB *mkb;
fp = _file_open(aacs, "AACS" DIR_SEP "MKB_RO.inf");
if (!fp) {
BD_DEBUG(DBG_AACS | DBG_CRIT, "Error opening MKB file (AACS/MKB_RO.inf)\n");
size = _read_file(aacs, "AACS" DIR_SEP "MKB_RO.inf", &data);
if (size < 4) {
X_FREE(data);
BD_DEBUG(DBG_AACS | DBG_CRIT, "Error reading MKB file (AACS/MKB_RO.inf)\n");
return NULL;
}
mkb = mkb_read(fp);
file_close(fp);
mkb = mkb_init(data, size);
if (!mkb) {
X_FREE(data);
}
return mkb;
}
......
......@@ -18,7 +18,6 @@
*/
#include "mkb.h"
#include "file/file.h"
#include "util/macro.h"
#include "util/logging.h"
#include "util/strutl.h"
......@@ -54,17 +53,17 @@ static const uint8_t *_record(MKB *mkb, uint8_t type, size_t *rec_len)
return NULL;
}
MKB *mkb_read(AACS_FILE_H *fp)
MKB *mkb_init(uint8_t *data, size_t len)
{
MKB *mkb = malloc(sizeof(MKB));
file_seek(fp, 0, SEEK_END);
mkb->size = file_tell(fp);
file_seek(fp, 0, SEEK_SET);
mkb->buf = malloc(mkb->size);
if (!mkb) {
BD_DEBUG(DBG_MKB | DBG_CRIT, "out of memory\n");
return NULL;
}
file_read(fp, mkb->buf, mkb->size);
mkb->size = len;
mkb->buf = data;
BD_DEBUG(DBG_MKB, "MKB size: %u\n", (unsigned)mkb->size);
BD_DEBUG(DBG_MKB, "MKB version: %d\n", mkb_version(mkb));
......@@ -72,16 +71,6 @@ MKB *mkb_read(AACS_FILE_H *fp)
return mkb;
}
MKB *mkb_init(uint8_t *data, int len)
{
MKB *mkb = malloc(sizeof(MKB));
mkb->size = len;
mkb->buf = data;
return mkb;
}
void mkb_close(MKB *mkb)
{
if (mkb) {
......
......@@ -29,8 +29,7 @@ typedef struct mkb MKB;
struct aacs_file_s;
BD_PRIVATE MKB *mkb_read(struct aacs_file_s *fp); // init MKB
BD_PRIVATE MKB *mkb_init(uint8_t *data, int len); // init MKB from data
BD_PRIVATE MKB *mkb_init(uint8_t *data, size_t len); // init MKB from data
BD_PRIVATE void mkb_close(MKB *mkb); // free MKB
BD_PRIVATE const uint8_t *mkb_data(MKB *mkb);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment