From c66afedb170f7ec96aa91c94cb86d50179be01c3 Mon Sep 17 00:00:00 2001 From: tYYGH Date: Thu, 21 Jan 2016 23:17:09 +0100 Subject: [PATCH] Fix hang if non-existing label is searched. --- README | 2 ++ cli/paperfind.sh | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README b/README index f67c179..a1bc2dc 100644 --- a/README +++ b/README @@ -24,6 +24,8 @@ The solution is to allow the web server user to execute a single command as anot * the command-line interface, that is run on the server by a user with read access to the documents; * the web interface, that is run on the web server, with no access to the documents save through the CLI interface. +Finally, all the input (search terms, etc.) is verified by the CLI script, so that any number of frontends can be written and benefit from the same strict controls. + = INSTALLATION AND DEPENDENCIES = The script may be copied anywhere. Its dependencies are standard, although I only tested on Debian: bash, find, gawk, sed, grep, file, ls. diff --git a/cli/paperfind.sh b/cli/paperfind.sh index ccf8025..fa2ca4f 100755 --- a/cli/paperfind.sh +++ b/cli/paperfind.sh @@ -102,7 +102,7 @@ Q) if [ ${#labels[*]} -gt 0 ]; then # This is an AND for l in "${labels[@]}"; do - found="$( + [ -n "$found" ] && found="$( eval grep -lF${q_ci:+i}e "$l" ${found//|/labels} 2>/dev/null \ | sed 's#labels$#|#')" done @@ -111,7 +111,7 @@ Q) # eval grep -lF${q_ci:+i}f <(printf '%s\n' "${labels[@]}") ${found//|/labels} 2>/dev/null \ # | sed 's#labels$#|#')" fi - if [ ${#words[*]} -gt 0 ]; then + if [ ${#words[*]} -gt 0 ] && [ -n "$found" ]; then # This is an AND tmpf="$( eval grep -Ho "'>[^<>]*/dev/null \