Explorar el Código

db_postgres(old API) FS#77: fix BLOBs with postgres

fix BLOBs with postgres, also add a null-termination as the other
SQL databases in order to be able to work with the presence modules
(cherry picked from commit 2e56720769913c55cacc83fe3a31f44f072e7590)
Henning Westerholt hace 15 años
padre
commit
a6141a3273
Se han modificado 1 ficheros con 4 adiciones y 2 borrados
  1. 4 2
      modules/db_postgres/km_val.c

+ 4 - 2
modules/db_postgres/km_val.c

@@ -72,16 +72,18 @@ int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const
 			LM_ERR("PQunescapeBytea failed\n");
 			return -7;
 		}
-		VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len);
+		VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len + 1);
 		if (VAL_BLOB(_v).s == NULL) {
 			LM_ERR("no private memory left\n");
 			PQfreemem(tmp_s);
 			return -8;
 		}
-		LM_DBG("allocate %d bytes memory for BLOB at %p", VAL_BLOB(_v).len, VAL_BLOB(_v).s);
+		LM_DBG("allocate %d bytes memory for BLOB at %p", VAL_BLOB(_v).len + 1, VAL_BLOB(_v).s);
 		memcpy(VAL_BLOB(_v).s, tmp_s, VAL_BLOB(_v).len);
 		PQfreemem(tmp_s);
 
+		VAL_BLOB(_v).s[VAL_BLOB(_v).len] = '\0';
+		VAL_BLOB(_v).len++;
 		VAL_TYPE(_v) = DB1_BLOB;
 		VAL_FREE(_v) = 1;