mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
db.pg: fix invalid memory access in res_to_rows (#20248)
This commit is contained in:
parent
944b9554bd
commit
06a536eff2
3 changed files with 26 additions and 2 deletions
|
@ -190,8 +190,7 @@ fn res_to_rows(res voidptr) []Row {
|
|||
row.vals << none
|
||||
} else {
|
||||
val := C.PQgetvalue(res, i, j)
|
||||
sval := unsafe { val.vstring() }
|
||||
row.vals << sval
|
||||
row.vals << unsafe { cstring_to_vstring(val) }
|
||||
}
|
||||
}
|
||||
rows << row
|
||||
|
|
24
vlib/db/pg/pg_test.v
Normal file
24
vlib/db/pg/pg_test.v
Normal file
|
@ -0,0 +1,24 @@
|
|||
module main
|
||||
|
||||
import db.pg
|
||||
|
||||
const query = 'SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen
|
||||
FROM pg_class c
|
||||
JOIN information_schema.tables ischema on ischema.table_name = c.relname
|
||||
JOIN pg_attribute a ON (a.attrelid = c.oid)
|
||||
JOIN pg_type t ON (t.oid = a.atttypid)
|
||||
WHERE
|
||||
a.attnum >= 0'
|
||||
|
||||
fn test_large_exec() {
|
||||
db := pg.connect(pg.Config{ user: 'postgres', password: 'secret', dbname: 'postgres' })!
|
||||
defer {
|
||||
db.close()
|
||||
}
|
||||
|
||||
rows := db.exec(query)!
|
||||
for row in rows {
|
||||
// We just need to access the memory to ensure it's properly allocated
|
||||
row.str()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue