[Home]

Summary:ASTERISK-20524: AMI improperly handles lines of exactly 1025 characters
Reporter:David M. Lee (dlee)Labels:
Date Opened:2012-10-05 12:49:05Date Closed:2015-04-14 11:40:17
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/ManagerInterface
Versions:1.8.16.0 Frequency of
Occurrence
Constant
Related
Issues:
Environment:Attachments:( 0) ami-line-length.sh
Description:I found this while working on my fix for AST-961, but didn't have a chance to really track it down.

Attached I have a really simple script I use to stimulate long-line errors in the AMI parser. If you send lines of 1024 characters or less, everything works as expected. If you send lines of 1026 characters or more, it will respond with a 'line too long' error (assuming you have [my fix for long line errors|https://reviewboard.asterisk.org/r/2142/]).

But if you send a 1025 character line exactly, AMI will read a bare newline immediately after the long line, terminating the message. This leads to an extra error response, which really confuses AMI libraries, such as [StarPy|https://github.com/asterisk-org/starpy].

{code:none}
# 1024 characters passes as expected
$ ./ami-line-length.sh 1024
== 1024 ==
Asterisk Call Manager/1.1
Response: Success
Message: Authentication accepted

Event: FullyBooted
Privilege: system,all
Status: Fully Booted

Response: Success
ActionID: 12345
Variable: foo
Value:

# 1026 characters fails as expected
[dlee@dlee-mac asterisk]$ ./ami-line-length.sh 1026
== 1026 ==
Asterisk Call Manager/1.1
Response: Success
Message: Authentication accepted

Event: FullyBooted
Privilege: system,all
Status: Fully Booted

Response: Error
ActionID: 12345
Message: Failed to parse message: line too long

# 1025 characters has an extra error response
# And, your command gets a 'Missing action' error instead of a 'line too long' error
== 1025 ==
Asterisk Call Manager/1.1
Response: Success
Message: Authentication accepted

Event: FullyBooted
Privilege: system,all
Status: Fully Booted

Response: Error
Message: Failed to parse message: line too long

Response: Error
ActionID: 12345
Message: Missing action in request

{code}
Comments:By: David M. Lee (dlee) 2012-10-05 12:49:43.228-0500

Script to cause AMI line length failures.

By: Matt Jordan (mjordan) 2012-10-05 16:01:54.856-0500

Wow that's weird.

By: Corey Farrell (coreyfarrell) 2014-06-11 10:29:29.210-0500

This error also occurs with 2049 and 4097 characters.  This seems to be reproducible with line length of 1024 * x + 1.  Honestly I'm more confused that cause the multiple failure messages for all lines > 1024.