Skip to content

Commit

Permalink
Merge pull request #69 from scanoss/5.4.3
Browse files Browse the repository at this point in the history
solve bug reading source files
  • Loading branch information
mscasso-scanoss authored Apr 21, 2024
2 parents 4d53e29 + 707e7cd commit 4c79d85
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 51 deletions.
4 changes: 2 additions & 2 deletions inc/scanoss.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define WFP_REC_LN 18

/* Log files */
#define SCANOSS_VERSION "5.4.2"
#define SCANOSS_VERSION "5.4.3"
#define SCAN_LOG "/tmp/scanoss_scan.log"
#define MAP_DUMP "/tmp/scanoss_map.dump"
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"
Expand Down Expand Up @@ -140,7 +140,7 @@ extern struct ldb_table oss_dependency;
extern struct ldb_table oss_license;
extern struct ldb_table oss_attribution;
extern struct ldb_table oss_cryptography;

extern struct ldb_table oss_sources;

extern bool first_file;
extern int max_vulnerabilities;
Expand Down
96 changes: 49 additions & 47 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct ldb_table oss_dependency;
struct ldb_table oss_license;
struct ldb_table oss_attribution;
struct ldb_table oss_cryptography;
struct ldb_table oss_sources;

component_item *ignore_components;
component_item *declared_components;

Expand All @@ -66,6 +68,48 @@ uint8_t trace_id[MD5_LEN];
bool trace_on;
bool lib_encoder_present = false;
#define LDB_VER_MIN "4.1.0"

void * lib_encoder_handle = NULL;
bool lib_encoder_load()
{
#ifndef SCANOSS_ENCODER_VERSION
/*set decode funtion pointer to NULL*/
lib_encoder_handle = dlopen("libscanoss_encoder.so", RTLD_NOW);
char * err;
if ((err = dlerror()))
{
scanlog("Lib scanoss-encoder was not detected. %s\n", err);
}

if (lib_encoder_handle)
{
scanlog("Lib scanoss-encoder present\n");
decrypt_data = dlsym(lib_encoder_handle, "scanoss_decode_table");
decrypt_mz = dlsym(lib_encoder_handle, "scanoss_decode_mz");
encoder_version = dlsym(lib_encoder_handle, "scanoss_encoder_version");
if ((err = dlerror()))
{
printf("%s - You may need to update libscanoss_encoder.so\n", err);
exit(EXIT_FAILURE);
}

char version[32] = "\0";
encoder_version(version);
scanlog("Lib scanoss-encoder version %s\n", version);
return true;
}
decrypt_data = standalone_decrypt_data;
decrypt_mz = NULL;
return false;
#else
decrypt_data = scanoss_decode_table;
decrypt_mz = scanoss_decode_mz;
encoder_version = scanoss_encoder_version;
scanlog("Using built-in encoder library v%s\n", SCANOSS_ENCODER_VERSION);
return false;
#endif
}

/* Initialize tables for the DB name indicated (defaults to oss) */
void initialize_ldb_tables(char *name)
{
Expand Down Expand Up @@ -121,8 +165,13 @@ void initialize_ldb_tables(char *name)
snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "cryptography");
oss_cryptography = ldb_read_cfg(dbtable);

snprintf(dbtable, MAX_ARGLN * 2, "%s/%s", oss_db_name, "sources");
oss_sources = ldb_read_cfg(dbtable);

kb_version_get();
osadl_load_file();

lib_encoder_present = lib_encoder_load();
}

/**
Expand Down Expand Up @@ -212,45 +261,6 @@ uint64_t read_flags()
return 0;
}


void * lib_encoder_handle = NULL;
bool lib_encoder_load()
{
#ifndef SCANOSS_ENCODER_VERSION
/*set decode funtion pointer to NULL*/
lib_encoder_handle = dlopen("libscanoss_encoder.so", RTLD_NOW);
char * err;
if ((err = dlerror()))
{
scanlog("Lib scanoss-encoder was not detected. %s\n", err);
}

if (lib_encoder_handle)
{
scanlog("Lib scanoss-encoder present\n");
decrypt_data = dlsym(lib_encoder_handle, "scanoss_decode_table");
decrypt_mz = dlsym(lib_encoder_handle, "scanoss_decode_mz");
encoder_version = dlsym(lib_encoder_handle, "scanoss_encoder_version");
if ((err = dlerror()))
{
printf("%s - You may need to update libscanoss_encoder.so\n", err);
exit(EXIT_FAILURE);
}
return true;
}
decrypt_data = standalone_decrypt_data;
decrypt_mz = NULL;
return false;
#else
decrypt_data = scanoss_decode_table;
decrypt_mz = scanoss_decode_mz;
encoder_version = scanoss_encoder_version;
scanlog("Using built-in encoder library v%s\n", SCANOSS_ENCODER_VERSION);
return false;
#endif
}


/**
* @brief //TODO
* @param argc //TODO
Expand Down Expand Up @@ -429,14 +439,6 @@ int main(int argc, char **argv)
/* Perform scan */
else
{
lib_encoder_present = lib_encoder_load();
if (lib_encoder_present && debug_on)
{
char version[32] = "\0";
encoder_version(version);
scanlog("Lib encoder present - version %s\n", version);
}

/* Validate target */
char *arg_target = argv[argc-1];
bool isfile = is_file(arg_target);
Expand Down
12 changes: 10 additions & 2 deletions src/mz.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ void mz_get_key(struct mz_job *job, char *key)
memcpy(mz_file_id, key, 4);

sprintf(mz_path, "%s/%s.mz", job->path, mz_file_id);
if (oss_sources.definitions & LDB_TABLE_DEFINITION_ENCRYPTED)
{
if (decrypt_mz)
strcat(mz_path, ".enc");
else
{
fprintf(stderr, "Encoder lib not available. Install libscanoss_encoder.so and try again\n");
exit(EXIT_FAILURE);
}
}
scanlog("MZ path: %s \n", mz_path);

if (decrypt_mz && access(mz_path, F_OK) != 0)
strcat(mz_path, ".enc");
/* Save path and key on job */
job->key = calloc(MD5_LEN, 1);
ldb_hex_to_bin(key, MD5_LEN * 2, job->key);
Expand Down

0 comments on commit 4c79d85

Please sign in to comment.