Skip to content

Commit

Permalink
Fix: Bug reported by the clang static analyzer.
Browse files Browse the repository at this point in the history
Description: Potential leak of memory pointed to by 'globals'
File: ./src/openvas.c
Line: 612

To fix this the following changes were done:
- Fix files_add_size_translation (), so the g_free is passed as destroy notifier, becasue the size is stored as string.
- creates a new function destroy_scan_globals() to free the struct.
- use the struct.
- update CmakeLists.txt
  • Loading branch information
jjnicola committed Oct 21, 2022
1 parent 9dabe7b commit efe513e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ include_directories (${GLIB_INCLUDE_DIRS} ${GLIB_JSON_INCLUDE_DIRS}

set (FILES bpf_share.c ftp_funcs.c vendorversion.c network.c plugutils.c pcap.c
scan_id.c strutils.c table_driven_lsc.c ipc.c ipc_openvas.c ipc_pipe.c
user_agent.c)
user_agent.c scanneraux.c)


# On windows we are always PIC and stack-protector is replaces by DEP
Expand Down
5 changes: 5 additions & 0 deletions misc/scanneraux.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <glib.h>
#include <gvm/base/nvti.h>
#include <gvm/util/kb.h>

struct scan_globals
{
GHashTable *files_translation;
Expand All @@ -54,4 +55,8 @@ struct script_infos
int denial_port;
int alive;
};

void
destroy_scan_globals (struct scan_globals *);

#endif /* not MISC_SCANNERAUX_H */
8 changes: 5 additions & 3 deletions src/openvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,14 @@ openvas (int argc, char *argv[], char *env[])

err = attack_network_init (globals, config_file);
if (err != 0)
return EXIT_FAILURE;

{
destroy_scan_globals (globals);
return EXIT_FAILURE;
}
attack_network (globals);

gvm_close_sentry ();
g_free (globals);
destroy_scan_globals (globals);
return EXIT_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ files_add_size_translation (struct scan_globals *globals, const char *file_hash,
// Register the mapping table if none there yet
if (trans == NULL)
{
trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
globals->files_size_translation = trans;
}

Expand Down

0 comments on commit efe513e

Please sign in to comment.