mirror of
https://github.com/vlang/v.git
synced 2025-09-09 15:27:05 -04:00
db.pg: fix invalid memory access in res_to_rows (#20248)
This commit is contained in:
parent
944b9554bd
commit
06a536eff2
@ -92,6 +92,7 @@ const skip_test_files = [
|
|||||||
'vlib/db/mysql/mysql_test.v', // mysql not installed
|
'vlib/db/mysql/mysql_test.v', // mysql not installed
|
||||||
'vlib/db/mysql/prepared_stmt_test.v', // mysql not installed
|
'vlib/db/mysql/prepared_stmt_test.v', // mysql not installed
|
||||||
'vlib/db/pg/pg_orm_test.v', // pg not installed
|
'vlib/db/pg/pg_orm_test.v', // pg not installed
|
||||||
|
'vlib/db/pg/pg_test.v', // pg not installed
|
||||||
]
|
]
|
||||||
// These tests are too slow to be run in the CI on each PR/commit
|
// These tests are too slow to be run in the CI on each PR/commit
|
||||||
// in the sanitized modes:
|
// in the sanitized modes:
|
||||||
|
@ -190,8 +190,7 @@ fn res_to_rows(res voidptr) []Row {
|
|||||||
row.vals << none
|
row.vals << none
|
||||||
} else {
|
} else {
|
||||||
val := C.PQgetvalue(res, i, j)
|
val := C.PQgetvalue(res, i, j)
|
||||||
sval := unsafe { val.vstring() }
|
row.vals << unsafe { cstring_to_vstring(val) }
|
||||||
row.vals << sval
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rows << row
|
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…
x
Reference in New Issue
Block a user