From 3713529f5a1b05c56526a55610ef3cf5dccb585e Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 4 Apr 2012 18:17:44 +0200 Subject: Error on 0-byte files No point in uploading a really empty file and it might even cause confusion to see an empty page when clicking the link. Signed-off-by: Florian Pritz --- fb-helper.c | 6 ++++++ fb.in | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/fb-helper.c b/fb-helper.c index ee6fe60..03c200c 100644 --- a/fb-helper.c +++ b/fb-helper.c @@ -277,6 +277,12 @@ int main(int argc, char *argv[]) goto cleanup; } + if (data_size == 0) { + fprintf(stderr, "Error: skipping 0-byte file: \"%s\"\n", file); + ret = 1; + goto cleanup; + } + forms[0].option = CURLFORM_BUFFER; forms[0].value = basename(file); forms[1].option = CURLFORM_BUFFERPTR; diff --git a/fb.in b/fb.in index 7d47ee8..0380777 100644 --- a/fb.in +++ b/fb.in @@ -69,6 +69,10 @@ request_helper() { if [ "$mode" = "u" ]; then basefilename=`basename -- "$file"` if [ "`$STAT -- "$file"`" -eq "0" ] || echo "$basefilename" | grep -F -q ","; then + if [ "`wc -c -- "$file" | cut -d\ -f1`" -eq "0" ]; then + echo "Error: skipping 0-byte file: \"$file\"" >&2 + return 1 + fi base64fn="`base64_encode "$basefilename"`" curl $CURLOPTS -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout else -- cgit v1.2.3-24-g4f1b