aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--erts/doc/src/erlang.xml9
-rw-r--r--erts/emulator/beam/packet_parser.c22
-rw-r--r--erts/emulator/test/decode_packet_SUITE.erl6
-rw-r--r--lib/kernel/doc/src/inet.xml4
4 files changed, 21 insertions, 20 deletions
diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml
index 42a4e6a999..1ea88a185f 100644
--- a/erts/doc/src/erlang.xml
+++ b/erts/doc/src/erlang.xml
@@ -724,9 +724,12 @@ false</pre>
size limit.</p>
</item>
<tag><c>{line_length, integer()}</c></tag>
- <item><p>Applies only to line oriented protocols
- (<c>line</c>, <c>http</c>). Lines longer than this
- will be truncated.</p>
+ <item><p>For packet type <c>line</c>, truncate lines longer
+ than the indicated length.</p>
+ <p>Option <c>line_length</c> also applies to <c>http*</c>
+ packet types as an alias for option <c>packet_size</c> in the
+ case when <c>packet_size</c> itself is not set. This usage is
+ only intended for backward compatibility.</p>
</item>
</taglist>
<pre>
diff --git a/erts/emulator/beam/packet_parser.c b/erts/emulator/beam/packet_parser.c
index 8c1662dc6f..4d4b6ea196 100644
--- a/erts/emulator/beam/packet_parser.c
+++ b/erts/emulator/beam/packet_parser.c
@@ -405,18 +405,22 @@ int packet_get_length(enum PacketParseType htype,
const char* ptr1 = ptr;
int len = plen;
+ if (!max_plen) {
+ /* This is for backward compatibility with old user of decode_packet
+ * that might use option 'line_length' to limit accepted length of
+ * http lines.
+ */
+ max_plen = trunc_len;
+ }
+
while (1) {
const char* ptr2 = memchr(ptr1, '\n', len);
if (ptr2 == NULL) {
if (max_plen != 0) {
- if (n > max_plen) /* packet full */
+ if (n >= max_plen) /* packet full */
goto error;
}
- else if (n >= trunc_len && trunc_len!=0) { /* buffer full */
- plen = trunc_len;
- goto done;
- }
goto more;
}
else {
@@ -425,8 +429,6 @@ int packet_get_length(enum PacketParseType htype,
if (*statep == 0) {
if (max_plen != 0 && plen > max_plen)
goto error;
- if (plen >= trunc_len && trunc_len != 0)
- plen = trunc_len;
goto done;
}
@@ -439,18 +441,12 @@ int packet_get_length(enum PacketParseType htype,
else {
if (max_plen != 0 && plen > max_plen)
goto error;
- if (plen >= trunc_len && trunc_len != 0)
- plen = trunc_len;
goto done;
}
}
else {
if (max_plen != 0 && plen > max_plen)
goto error;
- if (plen >= trunc_len && trunc_len != 0) {
- plen = trunc_len;
- goto done;
- }
goto more;
}
}
diff --git a/erts/emulator/test/decode_packet_SUITE.erl b/erts/emulator/test/decode_packet_SUITE.erl
index 55ef05079f..4acbe8c6e0 100644
--- a/erts/emulator/test/decode_packet_SUITE.erl
+++ b/erts/emulator/test/decode_packet_SUITE.erl
@@ -596,11 +596,9 @@ otp_9389(Config) when is_list(Config) ->
{more, undefined} = erlang:decode_packet(httph, Rest2, Opts),
{ok, {http_header,_,"Link",_,Link}, Rest3} =
erlang:decode_packet(httph, list_to_binary([Rest2, Pkt2]), Opts),
- true = (length(Link) =< 3000),
- {ok, {http_error, _}, Rest4} = erlang:decode_packet(httph, Rest3, Opts),
- {ok, {http_error, _}, Rest5} = erlang:decode_packet(httph, Rest4, Opts),
+ true = (length(Link) > 8000),
{ok, {http_header,_,'Content-Length',_,"0"}, <<"\r\n">>} =
- erlang:decode_packet(httph, Rest5, Opts),
+ erlang:decode_packet(httph, Rest3, Opts),
ok.
otp_9389_line(doc) -> ["Verify packet_size works correctly for line mode"];
diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml
index fad5af85bb..1a05b4ba99 100644
--- a/lib/kernel/doc/src/inet.xml
+++ b/lib/kernel/doc/src/inet.xml
@@ -573,6 +573,10 @@ fe80::204:acff:fe17:bf38
is longer than the max allowed length, the packet is
considered invalid. The same happens if the packet header
is too big for the socket receive buffer.</p>
+ <p>For line oriented protocols (<c>line</c>,<c>http*</c>),
+ option <c>packet_size</c> also guarantees that lines up to the
+ indicated length are accepted and not considered invalid due
+ to internal buffer limitations.</p>
</item>
<tag><c>{read_packets, Integer}</c>(UDP sockets)</tag>
<item>