Skip to content

Instantly share code, notes, and snippets.

@ThomasLocke
Created January 11, 2012 21:55
Show Gist options
  • Save ThomasLocke/1596992 to your computer and use it in GitHub Desktop.
Save ThomasLocke/1596992 to your computer and use it in GitHub Desktop.
AWS.Cookie patch suggestion
From 4e5765f68f37b2f770804fa394117d0e62f9bc9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=B8cke?= <[email protected]>
Date: Wed, 11 Jan 2012 17:08:52 +0100
Subject: [PATCH] Both of these searched the cookie strings in a very weak and
error prone manner. This has been updated to instead use
some of the available AWS tools so it's now much more
reliable.
Also did some minor tweaks to the Get functions that convert string values to
Integer and Float.
Thanks goes to Maciej Sobczak for finding this bug.
---
src/extended/aws-cookie.adb | 46 +++++++++++++++---------------------------
1 files changed, 17 insertions(+), 29 deletions(-)
diff --git a/src/extended/aws-cookie.adb b/src/extended/aws-cookie.adb
index dd1a8b0..917e95f 100644
--- a/src/extended/aws-cookie.adb
+++ b/src/extended/aws-cookie.adb
@@ -30,7 +30,7 @@
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
-with AWS.Headers;
+with AWS.Headers.Values;
with AWS.Messages;
with AWS.Response.Set;
with AWS.URL;
@@ -48,11 +48,15 @@ package body AWS.Cookie is
(Request : Status.Data;
Key : String) return Boolean
is
- Headers : constant AWS.Headers.List := Status.Header (Request);
- Cookie : constant String :=
- AWS.Headers.Get_Values (Headers, Messages.Cookie_Token);
+ use AWS.Headers;
begin
- return Index (Cookie, Key & "=") > 0;
+ return Values.Index
+ (Values.Split
+ (Get_Values
+ (Status.Header (Request),
+ Messages.Cookie_Token)),
+ Key,
+ True) > 0;
end Exists;
--------------
@@ -79,27 +83,13 @@ package body AWS.Cookie is
(Request : Status.Data;
Key : String) return String
is
- Headers : constant AWS.Headers.List := Status.Header (Request);
- Cookie : constant String :=
- AWS.Headers.Get_Values
- (Headers, Messages.Cookie_Token);
- Content_Start : constant Natural :=
- Index (Cookie, Key & "=") + Key'Length + 1;
- Content_End : Natural;
+ use AWS.Headers;
begin
- if Content_Start = 0 then
- return "";
- end if;
-
- Content_End := Index (Cookie, ";", From => Content_Start);
-
- if Content_End = 0 then
- Content_End := Cookie'Last;
- else
- Content_End := Content_End - 1;
- end if;
-
- return URL.Decode (Cookie (Content_Start .. Content_End));
+ return Values.Search
+ (Get_Values
+ (Status.Header (Request),
+ Messages.Cookie_Token),
+ Key);
end Get;
-----------
@@ -110,9 +100,8 @@ package body AWS.Cookie is
(Request : Status.Data;
Key : String) return Integer
is
- Value : constant String := Get (Request, Key);
begin
- return Integer'Value (Value);
+ return Integer'Value (Get (Request, Key));
exception
when Constraint_Error =>
return 0;
@@ -122,9 +111,8 @@ package body AWS.Cookie is
(Request : Status.Data;
Key : String) return Float
is
- Value : constant String := Get (Request, Key);
begin
- return Float'Value (Value);
+ return Float'Value (Get (Request, Key));
exception
when Constraint_Error =>
return 0.0;
--
1.7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment