From 570b1749da93f5e453766eceb0ed53ba86380309 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 6 Apr 2026 17:07:11 -0400 Subject: [PATCH] Fix PHP 8.2 TypeError crash in create_ticket_api.php on missing title generateTicketHash() passed $data['title'] to preg_match() before any input validation. In PHP 8.2, preg_match() with null subject throws TypeError, causing HTTP 500 with empty body. hwmonDaemon saw this as "Expecting value: line 1 column 1 (char 0)" and failed to create tickets on all nodes. Moved input validation before the hash call: missing or empty title now returns HTTP 400 with proper JSON error instead of crashing. Also removed the redundant late URL-encoded fallback. Co-Authored-By: Claude Sonnet 4.6 --- create_ticket_api.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/create_ticket_api.php b/create_ticket_api.php index 8ca211c..f08b56d 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -84,6 +84,22 @@ $conn->query($createTableSQL); $rawInput = file_get_contents('php://input'); $data = json_decode($rawInput, true); +// Validate required fields before any processing +if (!is_array($data) || empty($data['title'])) { + // Try URL-encoded fallback + if (empty($data['title'])) { + parse_str($rawInput, $urlData); + if (!empty($urlData['title'])) { + $data = $urlData; + } + } + if (!is_array($data) || empty($data['title'])) { + http_response_code(400); + echo json_encode(['success' => false, 'error' => 'title is required']); + exit; + } +} + // Generate hash from stable components function generateTicketHash($data) { // Extract device name if present (matches /dev/sdX, /dev/nvmeXnY patterns) @@ -167,11 +183,6 @@ if ($result->num_rows > 0) { // Force JSON content type for all incoming requests header('Content-Type: application/json'); -if (!$data) { - // Try parsing as URL-encoded data - parse_str($rawInput, $data); -} - // Generate ticket ID (9-digit format with leading zeros) $ticket_id = sprintf('%09d', mt_rand(1, 999999999));