From a7507044a8c177952e9e3cc8609474bd705b0721 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 2 Aug 2022 09:23:34 +0000 Subject: [PATCH] Fix validation of missing percentage arguments. --- usr.bin/tmux/arguments.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index 5bac7fadd90..4e6515ed0ba 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.55 2022/06/07 10:02:19 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.56 2022/08/02 09:23:34 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott @@ -895,6 +895,10 @@ args_percentage(struct args *args, u_char flag, long long minval, *cause = xstrdup("missing"); return (0); } + if (TAILQ_EMPTY(&entry->values)) { + *cause = xstrdup("empty"); + return (0); + } value = TAILQ_LAST(&entry->values, args_values)->string; return (args_string_percentage(value, minval, maxval, curval, cause)); } @@ -909,6 +913,10 @@ args_string_percentage(const char *value, long long minval, long long maxval, size_t valuelen = strlen(value); char *copy; + if (valuelen == 0) { + *cause = xstrdup("empty"); + return (0); + } if (value[valuelen - 1] == '%') { copy = xstrdup(value); copy[valuelen - 1] = '\0'; @@ -955,6 +963,10 @@ args_percentage_and_expand(struct args *args, u_char flag, long long minval, *cause = xstrdup("missing"); return (0); } + if (TAILQ_EMPTY(&entry->values)) { + *cause = xstrdup("empty"); + return (0); + } value = TAILQ_LAST(&entry->values, args_values)->string; return (args_string_percentage_and_expand(value, minval, maxval, curval, item, cause)); -- 2.20.1