Skip to content

Commit c4e152a

Browse files
committed
Add additional type checks
1 parent 1bb36e2 commit c4e152a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/envir.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,12 @@ R_BindingType R_GetBindingType(SEXP sym, SEXP env) {
785785
// Ideally we'd do it once, which would require manually walking
786786
// over the environment frame / hashtable and get the location to
787787
// inspect.
788-
788+
789+
if (TYPEOF(sym) != SYMSXP)
790+
error(_("not a symbol"));
791+
if (TYPEOF(env) != ENVSXP)
792+
error(_("not an environment"));
793+
789794
// This check must be before `Rf_findVarInFrame3()` because that
790795
// forces active bindings
791796
if (R_BindingIsActive(sym, env))
@@ -3627,6 +3632,11 @@ attribute_hidden Rboolean R_HasFancyBindings(SEXP rho)
36273632

36283633
// Equivalent to `substitute()`, but only supports promises
36293634
SEXP R_DelayedBindingExpression(SEXP sym, SEXP env) {
3635+
if (TYPEOF(sym) != SYMSXP)
3636+
error(_("not a symbol"));
3637+
if (TYPEOF(env) != ENVSXP)
3638+
error(_("not an environment"));
3639+
36303640
SEXP value = Rf_findVarInFrame3(env, sym, FALSE);
36313641

36323642
if (TYPEOF(value) != PROMSXP)
@@ -3640,6 +3650,11 @@ SEXP R_DelayedBindingExpression(SEXP sym, SEXP env) {
36403650
}
36413651

36423652
SEXP R_DelayedBindingEnvironment(SEXP sym, SEXP env) {
3653+
if (TYPEOF(sym) != SYMSXP)
3654+
error(_("not a symbol"));
3655+
if (TYPEOF(env) != ENVSXP)
3656+
error(_("not an environment"));
3657+
36433658
SEXP value = Rf_findVarInFrame3(env, sym, FALSE);
36443659

36453660
if (TYPEOF(value) != PROMSXP)
@@ -3652,6 +3667,11 @@ SEXP R_DelayedBindingEnvironment(SEXP sym, SEXP env) {
36523667
}
36533668

36543669
SEXP R_ForcedBindingExpression(SEXP sym, SEXP env) {
3670+
if (TYPEOF(sym) != SYMSXP)
3671+
error(_("not a symbol"));
3672+
if (TYPEOF(env) != ENVSXP)
3673+
error(_("not an environment"));
3674+
36553675
SEXP value = Rf_findVarInFrame3(env, sym, FALSE);
36563676

36573677
if (TYPEOF(value) != PROMSXP)

0 commit comments

Comments
 (0)