Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gcc-9 adn gcc-10 warnings #655

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
### Fixed
- Fix gcc-9 adn gcc-10 warnings. [#655](https://github.com/greenbone/openvas/pull/655)

### Removed

[20.08.2]: https://github.com/greenbone/openvas/compare/v20.8.0...openvas-20.08
Expand Down
23 changes: 18 additions & 5 deletions misc/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@
*/
#define G_LOG_DOMAIN "lib misc"

/**
* @brief Maximum length of an interface's name
*/
#define MAX_IFACE_NAME_LEN 64

struct interface_info
{
char name[64];
char name[MAX_IFACE_NAME_LEN];
struct in_addr addr;
struct in6_addr addr6;
struct in6_addr mask;
Expand Down Expand Up @@ -458,8 +463,14 @@ getinterfaces (int *howmany)
/* In case it is a stinkin' alias */
if ((p = strchr (ifr->ifr_name, ':')))
*p = '\0';
strncpy (mydevs[numinterfaces].name, ifr->ifr_name, 63);
mydevs[numinterfaces].name[63] = '\0';

memset (mydevs[numinterfaces].name, '\0', MAX_IFACE_NAME_LEN);
if (strlen (ifr->ifr_name) < MAX_IFACE_NAME_LEN)
memcpy (mydevs[numinterfaces].name, ifr->ifr_name,
strlen (ifr->ifr_name));
else
memcpy (mydevs[numinterfaces].name, ifr->ifr_name,
MAX_IFACE_NAME_LEN - 1);
numinterfaces++;
if (numinterfaces == 1023)
{
Expand Down Expand Up @@ -589,7 +600,7 @@ getipv4routes (struct myroute *myroutes, int *numroutes)
int numinterfaces;
char buf[1024];
char *p, *endptr;
char iface[64];
char iface[MAX_IFACE_NAME_LEN];
FILE *routez;
unsigned long dest;
struct in_addr inaddr;
Expand Down Expand Up @@ -623,6 +634,7 @@ getipv4routes (struct myroute *myroutes, int *numroutes)
continue;
}
strncpy (iface, p, sizeof (iface));
iface[MAX_IFACE_NAME_LEN - 1] = '\0';
if ((p = strchr (iface, ':')))
{
*p = '\0'; /* To support IP aliasing */
Expand Down Expand Up @@ -1075,7 +1087,7 @@ routethrough (struct in_addr *dest, struct in_addr *source)
} myroutes[MAXROUTES];
int numinterfaces = 0;
char *p, *endptr;
char iface[64];
char iface[MAX_IFACE_NAME_LEN];
static int numroutes = 0;
FILE *routez;
long best_match = -1;
Expand Down Expand Up @@ -1115,6 +1127,7 @@ routethrough (struct in_addr *dest, struct in_addr *source)
continue;
}
strncpy (iface, p, sizeof (iface));
iface[MAX_IFACE_NAME_LEN - 1] = '\0';
if ((p = strchr (iface, ':')))
{
*p = '\0'; /* To support IP aliasing */
Expand Down
1 change: 1 addition & 0 deletions nasl/nasl_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void
nasl_set_plugin_filename (const char *filename)
{
strncpy (debug_plugin_filename, filename, sizeof (debug_plugin_filename));
debug_plugin_filename[PATH_MAX - 1] = '\0';
}

const char *
Expand Down