Bug 40675: Fix SIP message corruption from embedded line endings

Patron messages containing carriage returns, line feeds, or CRLF
combinations can break SIP protocol communication since CR is used
as the SIP message terminator. This causes message parsing failures
and protocol errors in self-check systems.

The previous regex only handled single carriage returns (\r),
missing Windows CRLF (\r\n) and Unix LF (\n) sequences.

This patch normalizes all line ending variations to spaces to
prevent SIP message corruption while preserving message content.

Test plan:
1. Go to a patron record and click "Add message"
2. Select "Add message for OPAC..." from dropdown
3. In a text editor (e.g., Word), create a message with line breaks:
   "This is line one[Enter]This is line two[Enter]This is line three"
4. Copy and paste this multi-line text into the message box and save
5. Run the SIP emulator: misc/sip_cli_emulator.pl
6. Execute a patron information request for this patron
7. Before patch: Observe message breaks at line endings, corrupting
   the SIP response
8. Apply patch and restart SIP server
9. Repeat steps 5-6
10. After patch: Verify the message appears as single line with
    spaces replacing line breaks: "This is line one This is line two
    This is line three"
11. Test with different line ending types (Windows, Mac, Unix) to
    ensure all variations are handled correctly

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
[EDIT] Adjusted the comment in Sip.pm
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit affa3e62fd)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Bernard Scaife 2025-08-27 16:25:25 +01:00 committed by Paul Derscheid
parent 141275b2c2
commit 5709be47e4
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 2 additions and 2 deletions

View File

@ -97,8 +97,8 @@ sub add_field {
);
$value = '';
}
$value =~ s/\r/ /g; # CR terminates a sip message
# Protect against them in sip text fields
$value =~ s/\r\n|\r|\n/ /g; # CR or LF terminates a sip message
# Protect against them in sip text fields
# Replace any occurrences of the field delimiter in the
# field value with the HTML character entity