Converted egg parser to use cl_error_t instead of cl_egg_error_t.

pull/111/head
Micah Snyder 6 years ago
parent 8d30642000
commit 1606ce043c
  1. 344
      libclamav/egg.c
  2. 27
      libclamav/egg.h
  3. 22
      libclamav/scanners.c

File diff suppressed because it is too large Load Diff

@ -32,17 +32,6 @@
#include <clamav.h>
#include <others.h>
/**
* @brief Status return codes for egg extraction APIs.
*/
typedef enum {
EGG_OK = 0,
EGG_BREAK,
EGG_ENCRYPTED,
EGG_EMEM,
EGG_ERR
} cl_egg_error_t;
/**
* @brief Metadata list node structure modeled after the ClamAV RAR metadata structure.
*
@ -68,9 +57,9 @@ typedef struct cl_egg_metadata {
* @param hArchive [out] Handle to opened archive.
* @param comments [out] Array of null terminated archive comments, if present in archive. Array will be free'd by cli_egg_close()
* @param nComments [out] Number of archive comments in array.
* @return cl_egg_error_t EGG_OK if success.
* @return cl_error_t CL_SUCCESS if success.
*/
cl_egg_error_t cli_egg_open(
cl_error_t cli_egg_open(
fmap_t* map,
size_t sfx_offset,
void** hArchive,
@ -82,9 +71,9 @@ cl_egg_error_t cli_egg_open(
*
* @param hArchive An open EGG archive handle from cli_egg_open()
* @param file_metadata Metadata describing the next file to be extracted (or skipped).
* @return cl_egg_error_t EGG_OK if success.
* @return cl_error_t CL_SUCCESS if success.
*/
cl_egg_error_t cli_egg_peek_file_header(
cl_error_t cli_egg_peek_file_header(
void* hArchive,
cl_egg_metadata* file_metadata);
@ -98,9 +87,9 @@ cl_egg_error_t cli_egg_peek_file_header(
* @param filename [out] The filename of the extracted file, in UTF-8.
* @param output_buffer [out] A malloc'd buffer of the file contents. Must be free()'d by caller. Set to NULL on failure.
* @param output_buffer_length [out] Size of buffer in bytes.
* @return cl_egg_error_t EGG_OK if success.
* @return cl_error_t CL_SUCCESS if success.
*/
cl_egg_error_t cli_egg_extract_file(
cl_error_t cli_egg_extract_file(
void* hArchive,
const char** filename,
const char** output_buffer,
@ -112,9 +101,9 @@ cl_egg_error_t cli_egg_extract_file(
* This is useful to skip things like directories, encrypted files, or file that are too large.
*
* @param hArchive An open EGG archive handle from cli_egg_open()
* @return cl_egg_error_t EGG_OK if success.
* @return cl_error_t CL_SUCCESS if success.
*/
cl_egg_error_t cli_egg_skip_file(void* hArchive);
cl_error_t cli_egg_skip_file(void* hArchive);
/**
* @brief Close the handle to the EGG archive and free the associated resources.

@ -606,7 +606,7 @@ done:
static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
{
cl_error_t status = CL_EPARSE;
cl_egg_error_t egg_ret = EGG_ERR;
cl_error_t egg_ret = CL_EPARSE;
char *buffer = NULL;
size_t buffer_len = 0;
@ -662,12 +662,12 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
* Open the archive.
*/
if (CL_SUCCESS != (egg_ret = cli_egg_open(*ctx->fmap, sfx_offset, &hArchive, &comments, &nComments))) {
if (egg_ret == EGG_ENCRYPTED) {
if (egg_ret == CL_EUNPACK) {
cli_dbgmsg("EGG: Encrypted main header\n");
status = CL_EUNPACK;
goto done;
}
if (egg_ret == EGG_EMEM) {
if (egg_ret == CL_EMEM) {
status = CL_EMEM;
goto done;
} else {
@ -750,18 +750,18 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
* Get the header information for the next file in the archive.
*/
egg_ret = cli_egg_peek_file_header(hArchive, &metadata);
if (egg_ret != EGG_OK) {
if (egg_ret == EGG_ENCRYPTED) {
if (egg_ret != CL_SUCCESS) {
if (egg_ret == CL_EUNPACK) {
/* Found an encrypted file header, must skip. */
cli_dbgmsg("EGG: Encrypted file header, unable to reading file metadata and file contents. Skipping file...\n");
nEncryptedFilesFound += 1;
if (EGG_OK != cli_egg_skip_file(hArchive)) {
if (CL_SUCCESS != cli_egg_skip_file(hArchive)) {
/* Failed to skip! Break extraction loop. */
cli_dbgmsg("EGG: Failed to skip file. EGG archive extraction has failed.\n");
break;
}
} else if (egg_ret == EGG_BREAK) {
} else if (egg_ret == CL_BREAK) {
/* No more files. Break extraction loop. */
cli_dbgmsg("EGG: No more files in archive.\n");
break;
@ -793,7 +793,7 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
/* Entry is a directory. Skip. */
cli_dbgmsg("EGG: Found directory. Skipping to next file.\n");
if (EGG_OK != cli_egg_skip_file(hArchive)) {
if (CL_SUCCESS != cli_egg_skip_file(hArchive)) {
/* Failed to skip! Break extraction loop. */
cli_dbgmsg("EGG: Failed to skip directory. EGG archive extraction has failed.\n");
break;
@ -805,7 +805,7 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
cli_dbgmsg("EGG: Next file is too large (%" PRIu64 " bytes); it would exceed max scansize. Skipping to next file.\n", metadata.unpack_size);
if (EGG_OK != cli_egg_skip_file(hArchive)) {
if (CL_SUCCESS != cli_egg_skip_file(hArchive)) {
/* Failed to skip! Break extraction loop. */
cli_dbgmsg("EGG: Failed to skip file. EGG archive extraction has failed.\n");
break;
@ -815,7 +815,7 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
cli_dbgmsg("EGG: Encrypted file, unable to extract file contents. Skipping file...\n");
nEncryptedFilesFound += 1;
if (EGG_OK != cli_egg_skip_file(hArchive)) {
if (CL_SUCCESS != cli_egg_skip_file(hArchive)) {
/* Failed to skip! Break extraction loop. */
cli_dbgmsg("EGG: Failed to skip file. EGG archive extraction has failed.\n");
break;
@ -831,7 +831,7 @@ static cl_error_t cli_scanegg(cli_ctx *ctx, size_t sfx_offset)
cli_dbgmsg("EGG: Extracting file: %s\n", metadata.filename);
egg_ret = cli_egg_extract_file(hArchive, (const char **)&extract_filename, (const char **)&extract_buffer, &extract_buffer_len);
if (egg_ret != EGG_OK) {
if (egg_ret != CL_SUCCESS) {
/*
* Some other error extracting the file
*/

Loading…
Cancel
Save