Skip to content

Commit

Permalink
Fix: setting stack buffer to NULL
Browse files Browse the repository at this point in the history
Since buffer within pluginlaunch.c is within the stack it cannot be
NULL. This fixes that oversight.

I'm unsure why we even double check for the buffer to be empty when it
is already indicated by len of fread.
  • Loading branch information
nichtsfrei committed Oct 3, 2024
1 parent 3b5707b commit a802306
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pluginlaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ plugin_timeout (nvti_t *nvti)
static int
get_available_memory ()
{
char buf[8192] = NULL;
char buf[8192];
char *hit = NULL;
FILE *fd = NULL;
size_t len;
memset (buf, 0, sizeof (buf));

fd = fopen ("/proc/meminfo", "r");
if (fd == NULL)
Expand All @@ -411,7 +412,11 @@ get_available_memory ()
}
len = fread (buf, 1, sizeof (buf) - 1, fd);
fclose (fd);
if (len == 0 || buf == NULL)
// if len is less then 0, then there was an error reading the file
// and we should check errno. Currently it is ignored because
// the caller just wants to know if memory is available and we asumme
// that there is none on error.
if (len <= 0)
{
g_warning ("Couldn't read /proc/meminfo");
return 0;
Expand Down

0 comments on commit a802306

Please sign in to comment.