Skip to content

Commit

Permalink
Merge pull request #5669 from larsewi/crash-3.21.x
Browse files Browse the repository at this point in the history
libpromises/evalfunction: Do not crash w/o arguments (3.21.x)
  • Loading branch information
larsewi authored Dec 19, 2024
2 parents eb8ffc9 + 9df186f commit ba5bc0a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -5697,6 +5697,14 @@ 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)
{
assert(fp != NULL);

if (finalargs == NULL)
{
Log(LOG_LEVEL_ERR, "Function '%s' requires at least one argument", fp->name);
return FnFailure();
}

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

Expand Down Expand Up @@ -5761,6 +5769,14 @@ static FnCallResult FnCallIsIpInSubnet(ARG_UNUSED EvalContext *ctx,
ARG_UNUSED const Policy *policy,
const FnCall *fp, const Rlist *finalargs)
{
assert(fp != NULL);

if (finalargs == NULL)
{
Log(LOG_LEVEL_ERR, "Function '%s' requires at least one argument", fp->name);
return FnFailure();
}

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

Expand Down Expand Up @@ -6878,6 +6894,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 ba5bc0a

Please sign in to comment.