From 7b95b379aa68634f4ad5453cc16f484bbe2815d7 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 17:37:59 -0400 Subject: [PATCH 1/5] dnsexit2: Fix extraction and processing of JSON response body --- ddclient.in | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ddclient.in b/ddclient.in index 2cbd994..6946515 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4215,17 +4215,14 @@ sub nic_dnsexit2_update { failed("Full reply\n%s", $reply) unless opt('verbose'); next; } - - # Strip HTTP response headers - (my $strip_status) = ($reply =~ s/^[\s\S]*?(?=\{"code":)//); - debug("strip_status"); - debug("%s", $strip_status); - if ($strip_status) { + my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr); + debug("body\n%s", $body); + if ($body ne $reply) { debug("HTTP headers are stripped."); } else { warning("Unexpected: no HTTP headers stripped!"); } - my $response = decode_json($reply); + my $response = decode_json($body); if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Response:"); From d28c8ea7add9b721b0fb4560fe91ed0f34ed70e5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 17:56:51 -0400 Subject: [PATCH 2/5] dnsexit2: Delete unnecessary debug messages --- ddclient.in | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ddclient.in b/ddclient.in index 6946515..7b4350a 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4216,12 +4216,6 @@ sub nic_dnsexit2_update { next; } my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr); - debug("body\n%s", $body); - if ($body ne $reply) { - debug("HTTP headers are stripped."); - } else { - warning("Unexpected: no HTTP headers stripped!"); - } my $response = decode_json($body); if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected \"code\" and \"message\" keys in server response."); From 24a22092ca7cd3e532042a159e57c5b84688aac2 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 18:02:01 -0400 Subject: [PATCH 3/5] dnsexit2: Don't croak if JSON decoding fails --- ddclient.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 7b4350a..6811588 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4216,7 +4216,11 @@ sub nic_dnsexit2_update { next; } my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr); - my $response = decode_json($body); + my $response = eval { decode_json($body); }; + if (!$response) { + failed("failed to parse response: $@"); + next; + } if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Response:"); From f7f4856b935a3e048d8723c28711d8ef6dbf0f7d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 18:02:45 -0400 Subject: [PATCH 4/5] dnsexit2: Combine related log messages --- ddclient.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ddclient.in b/ddclient.in index 6811588..83ac577 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4222,9 +4222,8 @@ sub nic_dnsexit2_update { next; } if (!defined($response->{'code'}) || !defined($response->{'message'})) { - failed("Did not receive expected \"code\" and \"message\" keys in server response."); - failed("Response:"); - failed("%s", $response); + failed("Did not receive expected 'code' and 'message' keys in server response:\n%s", + $response); next; } my %codemeaning = ( From f976b771d499f3e2a0222f2b51a788c589b9aa68 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 30 May 2024 18:18:55 -0400 Subject: [PATCH 5/5] dnsexit2: Fix logging of erroneous response body --- ddclient.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 83ac577..cbd009a 100755 --- a/ddclient.in +++ b/ddclient.in @@ -4223,7 +4223,7 @@ sub nic_dnsexit2_update { } if (!defined($response->{'code'}) || !defined($response->{'message'})) { failed("Did not receive expected 'code' and 'message' keys in server response:\n%s", - $response); + $body); next; } my %codemeaning = (