From bf2356ec08789f4f59a288b140a3c0c9924cf038 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 9 Aug 2026 04:13:00 +0000 Subject: [PATCH] Add missing input validation for exported functions icci and vuongtest --- .jules/sentinel.md | 4 ++++ R/icci.R | 2 ++ R/vuongtest.R | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index bc5c6e1..6811239 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -12,3 +12,7 @@ **Vulnerability:** Raw `stop()` and `warning()` calls without `call. = FALSE` in `llcont.R` and `vuongtest.R` exposed execution stack/call details when raised. **Learning:** While some instances of `stop()` inside `tryCatch()` were previously fixed to hide the call stack, other standalone exceptions and warnings still leaked call context. Security must be consistently applied across the entire codebase. **Prevention:** Always set `call. = FALSE` when using `stop()` or `warning()` to enforce a secure-by-default boundary and prevent internal execution paths from being disclosed to the end user. +## 2024-08-09 - [Input Validation and Error Handling] +**Vulnerability:** Unvalidated arguments passed to exported functions bypass top-level `stop(..., call. = FALSE)` safeguards and trigger raw R errors deep inside internal logic, leaking internal execution contexts. +**Learning:** R does not enforce type/length constraints on function arguments natively. Supplying unexpected types or multiple values (e.g., `conf.level="0.95"` or `nested=c(TRUE, FALSE)`) causes operations like `1 - conf.level` or `if(nested)` to throw base R errors, which exposes the execution stack to stdout. +**Prevention:** Always strictly validate the type, length, and bounds of user inputs at the very beginning of exported functions and fail securely using `stop(..., call. = FALSE)`. diff --git a/R/icci.R b/R/icci.R index f22278a..61f5499 100644 --- a/R/icci.R +++ b/R/icci.R @@ -65,6 +65,8 @@ #' @export icci <- function(object1, object2, conf.level=.95, ll1=llcont, ll2=llcont) { + if(!is.numeric(conf.level) || length(conf.level) != 1 || is.na(conf.level) || conf.level <= 0 || conf.level >= 1) stop("Argument 'conf.level' must be a single numeric value strictly between 0 and 1", call. = FALSE) + ## check objects, issue warnings/errors, get classes/calls obinfo <- check.obj(object1, object2) callA <- obinfo$callA; classA <- obinfo$classA diff --git a/R/vuongtest.R b/R/vuongtest.R index 2bdfbf6..d7a170e 100644 --- a/R/vuongtest.R +++ b/R/vuongtest.R @@ -98,6 +98,9 @@ #' @export vuongtest <- function(object1, object2, nested=FALSE, adj="none", ll1=llcont, ll2=llcont, score1=NULL, score2=NULL, vc1=vcov, vc2=vcov) { + if(!is.logical(nested) || length(nested) != 1 || is.na(nested)) stop("Argument 'nested' must be a single logical value", call. = FALSE) + if(!is.character(adj) || length(adj) != 1 || !(adj %in% c("none", "aic", "bic"))) stop("Argument 'adj' must be one of 'none', 'aic', or 'bic'", call. = FALSE) + ## check objects, issue warnings/errors, get classes/calls obinfo <- check.obj(object1, object2) callA <- obinfo$callA; classA <- obinfo$classA