~nytpu/tlsada

0881e702594db989d3d2fccd28cead0d91f86dfb — nytpu 1 year, 11 months ago bf8a3de
TLS.Get_Delim: Fix Encountered_Delim being set erroneously

Fix an issue where Encountered_Delim would be falsely set to True if the length
limit of the string is exceeded.
1 files changed, 31 insertions(+), 23 deletions(-)

M src/tls.adb
M src/tls.adb => src/tls.adb +31 -23
@@ 52,18 52,19 @@ package body TLS is
		-- read a new line, but data won't be dropped once we've successfully
		-- read.
		Character'Read(Stream, C);
		Encountered_Delim := True;
		Encountered_Delim := False;
		loop
			begin
				exit when Is_In(C, Delimeters);
				if Is_In(C, Delimeters) then
					Encountered_Delim := True;
					exit;
				end if;
				Append(O, C);
				exit when Max_Length > 0 and Length(O) >= Max_Length;
				Character'Read(Stream, C);

			exception
				when End_Error =>
						Encountered_Delim := False;
						exit;
				when End_Error => exit;
			end;
		end loop;
		return To_String(O);


@@ 80,6 81,7 @@ package body TLS is
		C : Character;
		O : Unbounded_String := Null_Unbounded_String;
	begin
		Encountered_Delim := False;
		-- Same deal as the alternate Get_Delim version
		Character'Read(Stream, Sliding(Sliding'First));
		for I in Sliding'First + 1 .. Sliding'Last loop


@@ 87,28 89,34 @@ package body TLS is
				Character'Read(Stream, Sliding(I));
			exception
				when End_Error =>
					Encountered_Delim := False;
					return Sliding(Sliding'First .. I - 1);
			end;
		end loop;
		Encountered_Delim := True;
		if Sliding /= Delimeter then
			loop
				begin
					Character'Read(Stream, C);
					Append(O, Sliding(Sliding'First));
					exit when Max_Length > 0 and Length(O) >= Max_Length;
					Sliding := Sliding(Sliding'First + 1 .. Sliding'Last) & C;
					exit when Sliding = Delimeter;

				exception
					when End_Error =>
						Encountered_Delim := False;
						Append(O, Sliding);
						exit;
				end;
			end loop;
		if Sliding = Delimeter then
			Encountered_Delim := True;
			return "";
		end if;

		loop
			begin
				Character'Read(Stream, C);
				Append(O, Sliding(Sliding'First));
				if Max_Length > 0 and Length(O) >= (Max_Length - Delimeter'Length) then
					Append(O, Sliding(Sliding'First + 1 .. Sliding'Last));
					exit;
				end if;
				Sliding := Sliding(Sliding'First + 1 .. Sliding'Last) & C;
				if Sliding = Delimeter then
					Encountered_Delim := True;
					exit;
				end if;

			exception
				when End_Error =>
					Append(O, Sliding);
					exit;
			end;
		end loop;
		return To_String(O);
	end Get_Delim;