diff --git a/apps/app_stack.c b/apps/app_stack.c
index 2e982b956c30a043a6feb4262bd964d444d3be32..20b03087f3958cd8328a82509099e5ca11131569 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -763,6 +763,12 @@ static int peek_read(struct ast_channel *chan, const char *cmd, char *data, char
 	}
 
 	AST_STANDARD_RAW_ARGS(args, data);
+
+	if (ast_strlen_zero(args.n) || ast_strlen_zero(args.name)) {
+		ast_log(LOG_ERROR, "LOCAL_PEEK requires parameters n and varname\n");
+		return -1;
+	}
+
 	n = atoi(args.n);
 	*buf = '\0';
 
@@ -802,6 +808,11 @@ static int stackpeek_read(struct ast_channel *chan, const char *cmd, char *data,
 	data = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, data);
 
+	if (ast_strlen_zero(args.n) || ast_strlen_zero(args.which)) {
+		ast_log(LOG_ERROR, "STACK_PEEK requires parameters n and which\n");
+		return -1;
+	}
+
 	n = atoi(args.n);
 	if (n <= 0) {
 		ast_log(LOG_ERROR, "STACK_PEEK must be called with a positive peek value\n");