Commits

Maciej Fijalkowski committed 8bc877a

asserts for length

  • Participants
  • Parent commits aa12a90

Comments (0)

Files changed (2)

pypy/module/postgresql/interp_adapters.py

                 raw_escaped = libpq.PQescapeByteaConn(
                     self.w_connection.pgconn, buf, len(buf), to_len
                 )
-            escaped = rffi.charp2strn(raw_escaped, to_len[0])
+            lgt = to_len[0]
+            assert lgt >= 0
+            escaped = rffi.charp2strn(raw_escaped, lgt)
             libpq.PQfreemem(rffi.cast(rffi.VOIDP, raw_escaped))
             res = "'%s'::bytea" % escaped
             if self.w_connection is not None:

pypy/module/postgresql/interp_types.py

 
     def cast(self, space, value, length, cursor):
         if self.w_py_caster is not None:
+            assert length >= 0
             return space.call_function(self.w_py_caster,
                 space.wrap(rffi.charp2strn(value, length)),
                 cursor,
     return w_val
 
 def cast_string(space, value, length, cursor):
+    assert length >= 0
     return space.wrap(rffi.charp2strn(value, length))
 
 def cast_longinteger(space, value, length, cursor):
+    assert length >= 0
     w_s = space.wrap(rffi.charp2strn(value, length))
     return space.call_function(space.w_long, w_s)
 
 def cast_integer(space, value, length, cursor):
+    assert length >= 0    
     return space.wrap(int(rffi.charp2strn(value, length)))
 
 def cast_float(space, value, length, cursor):
+    assert length >= 0
     s = rffi.charp2strn(value, length)
     if s == "NaN":
         n = NAN
 def cast_decimal(space, value, length, cursor):
     from pypy.module.postgresql.interp_state import get
 
+    assert length >= 0
     n = rffi.charp2strn(value, length)
     return space.call_function(get(space).w_Decimal, space.wrap(n))
 
     return space.wrap(value[0] == "t")
 
 def cast_generic_array(space, value, length, cursor):
+    assert length >= 0
     s = rffi.charp2strn(value, length)
     assert s[0] == "{" and s[-1] == "}"
     i = 1
     from pypy.module.postgresql.interp_state import get
 
     encoding = get(space).encodings[cursor.w_connection.encoding]
+    assert length >= 0
     s = rffi.charp2strn(value, length)
     w_s = space.wrap(s)
     return space.call_method(w_s, "decode", space.wrap(encoding))
 def cast_datetime(space, value, length, cursor):
     from pypy.module.postgresql.interp_state import get
 
+    assert length >= 0
     s = rffi.charp2strn(value, length)
     date, time = s.split(" ")
     w_date = _parse_date(space, date)
     return space.call_method(get(space).w_DateTime, "combine", w_date, w_time)
 
 def cast_date(space, value, length, cursor):
+    assert length >= 0
     date = rffi.charp2strn(value, length)
     return _parse_date(space, date)
 
 def cast_time(space, value, length, cursor):
+    assert length >= 0
     time = rffi.charp2strn(value, length)
     return _parse_time(space, time, cursor)
 
     part = 0
     skip_to_space = False
 
+    assert length >= 0
     s = rffi.charp2strn(value, length)
     for c in s:
         if skip_to_space: