Skip to content

Commit

Permalink
libpromises/evalfunction: Do not crash w/o arguments
Browse files Browse the repository at this point in the history
Do not crash cf-promises if no argument is given for following
functions:
* readfile
* iprange
* isipinsubnet
  • Loading branch information
btriller committed Nov 20, 2024
1 parent 95c90e1 commit 8979788
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -5730,6 +5730,12 @@ static FnCallResult FnCallFormat(EvalContext *ctx, ARG_UNUSED const Policy *poli
static FnCallResult FnCallIPRange(EvalContext *ctx, ARG_UNUSED const Policy *policy,
const FnCall *fp, const Rlist *finalargs)
{
if (finalargs == NULL)
{
Log(LOG_LEVEL_ERR, "Function '%s' requires at least one argument", fp->name);

Check notice

Code scanning / CodeQL

Pointer argument is dereferenced without checking for NULL Note

Parameter fp in FnCallIPRange() is dereferenced without an explicit null-check
return FnFailure();
}

const char *range = RlistScalarValue(finalargs);
const Rlist *ifaces = finalargs->next;

Expand Down Expand Up @@ -5794,6 +5800,12 @@ static FnCallResult FnCallIsIpInSubnet(ARG_UNUSED EvalContext *ctx,
ARG_UNUSED const Policy *policy,
const FnCall *fp, const Rlist *finalargs)
{
if (finalargs == NULL)
{
Log(LOG_LEVEL_ERR, "Function '%s' requires at least one argument", fp->name);

Check notice

Code scanning / CodeQL

Pointer argument is dereferenced without checking for NULL Note

Parameter fp in FnCallIsIpInSubnet() is dereferenced without an explicit null-check
return FnFailure();
}

const char *range = RlistScalarValue(finalargs);
const Rlist *ips = finalargs->next;

Expand Down Expand Up @@ -6911,6 +6923,12 @@ static FnCallResult FnCallEval(EvalContext *ctx, ARG_UNUSED const Policy *policy

static FnCallResult FnCallReadFile(ARG_UNUSED EvalContext *ctx, ARG_UNUSED const Policy *policy, ARG_UNUSED const FnCall *fp, const Rlist *finalargs)
{
if (finalargs == NULL)
{
Log(LOG_LEVEL_ERR, "Function 'readfile' requires at least one argument");
return FnFailure();
}

char *filename = RlistScalarValue(finalargs);
const Rlist *next = finalargs->next; // max_size argument, default to inf:
long maxsize = next ? IntFromString(RlistScalarValue(next)) : IntFromString("inf");
Expand Down

0 comments on commit 8979788

Please sign in to comment.