Skip to content
Snippets Groups Projects
Verified Commit a7677b32 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

fake: Make sure the name and passwords are properly escaped

These fields are byte arrays and we have strings, python needs to be
told explicitly to convert/use different escaping.
parent e98a31e7
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ import activity ...@@ -25,6 +25,7 @@ import activity
import socket import socket
import protocol import protocol
import database import database
import psycopg2
logger = logging.getLogger(name='fake') logger = logging.getLogger(name='fake')
...@@ -61,10 +62,14 @@ def store_logs(message, client, now, version): ...@@ -61,10 +62,14 @@ def store_logs(message, client, now, version):
for i in range(0, info_count): for i in range(0, info_count):
(kind_i,) = struct.unpack('!B', message[0]) (kind_i,) = struct.unpack('!B', message[0])
(content, message) = protocol.extract_string(message[1:]) (content, message) = protocol.extract_string(message[1:])
# Twisted gives us the message as a string. The name and password
# columns are bytea in postgres. This needs to be resolved by
# a conversion wrapper (because python seems to use escaping, not
# bound params)
if kind_i == 0: if kind_i == 0:
name = content name = psycopg2.Binary(content)
elif kind_i == 1: elif kind_i == 1:
passwd = content passwd = psycopg2.Binary(content)
elif kind_i == 2: elif kind_i == 2:
reason = content reason = content
values.append((now, age, tp, rem_address, loc_address, rem_port, name, passwd, reason, client, code)) values.append((now, age, tp, rem_address, loc_address, rem_port, name, passwd, reason, client, code))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment