From 18f63222f8a9f6463fce1fc79140db4704682600 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 11 Oct 2023 13:50:46 -0400 Subject: [PATCH] Spamnoticer - addToSpamNoticer, guard against null files field --- inc/spamnoticer.php | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/inc/spamnoticer.php b/inc/spamnoticer.php index 802f7c75..70c1e9e7 100644 --- a/inc/spamnoticer.php +++ b/inc/spamnoticer.php @@ -150,29 +150,31 @@ function addToSpamNoticer($config, $post, $boardname, BanFormFieldsForSpamnotice $attachments = array(); - foreach ($post->files as $file) { - $key = $file->file_id . '.' . $file->extension; - $file_info = $form_info->files_info[$key]; - $thumb_uri - = $config['spam_noticer']['imageboard_root'] - . $board['uri'] - . '/' . $config['dir']['thumb'] - . $file->file_id - . '.png'; + if (isset($post->files) && is_array($post->files)) { + foreach ($post->files as $file) { + $key = $file->file_id . '.' . $file->extension; + $file_info = $form_info->files_info[$key]; + $thumb_uri + = $config['spam_noticer']['imageboard_root'] + . $board['uri'] + . '/' . $config['dir']['thumb'] + . $file->file_id + . '.png'; - $a = array( - 'filename' => $file->filename, - 'mimetype' => $file->type ? $file->type : mime_content_type($file->tmp_name), - 'md5_hash' => $file->hash, - 'thumbnail_url' => $thumb_uri, - 'is_spam' => $file_info->is_spam - ); + $a = array( + 'filename' => $file->filename, + 'mimetype' => $file->type ? $file->type : mime_content_type($file->tmp_name), + 'md5_hash' => $file->hash, + 'thumbnail_url' => $thumb_uri, + 'is_spam' => $file_info->is_spam + ); - if ($file_info->is_illegal) { - $a['is_illegal'] = true; + if ($file_info->is_illegal) { + $a['is_illegal'] = true; + } + + $attachments[] = $a; } - - $attachments[] = $a; } $json_payload = [