Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix segfault when Dataset#yield_hash_rows is passed a nil value when …

…using ruby pg 0.18+, bump version to 1.6.12 (Fixes #19)

This can happen when swallowing errors inside Database#log_yield.

This issue only affected sequel_pg 1.6.11, as the bug was in the
pg 0.18+ support code and older versions of sequel_pg do not
support pg 0.18+.
  • Loading branch information...
commit 79c768d9508c55f55db3f20331b9631b85ff97f0 1 parent 3cf5f64
@jeremyevans authored
Showing with 12 additions and 4 deletions.
  1. +4 −0 CHANGELOG
  2. +7 −3 ext/sequel_pg/sequel_pg.c
  3. +1 −1  sequel_pg.gemspec
View
4 CHANGELOG
@@ -1,3 +1,7 @@
+=== 1.6.12 (2015-03-23)
+
+* Fix segfault when Dataset#yield_hash_rows is passed a nil value when using ruby pg 0.18+ (jeremyevans) (#19)
+
=== 1.6.11 (2014-11-04)
* Work with ruby pg 0.18+ (currently a prerelease) (jeremyevans)
View
10 ext/sequel_pg/sequel_pg.c
@@ -51,8 +51,8 @@ PGconn* pg_get_pgconn(VALUE);
PGresult* pgresult_get(VALUE);
/* Normalize access to data objects for both old and new versions of pg gem */
-#define GetPGconn(_val, _var) if (unwrap_structs) {_var = pg_get_pgconn(_val);} else {Data_Get_Struct(_val, PGconn, _var);}
-#define GetPGresult(_val, _var) if (unwrap_structs) {_var = pgresult_get(_val);} else {Data_Get_Struct(_val, PGresult, _var);}
+#define GetPGconn(_val, _var) if (unwrap_structs) {Check_Type(_val, T_DATA); _var = pg_get_pgconn(_val);} else {Data_Get_Struct(_val, PGconn, _var);}
+#define GetPGresult(_val, _var) if (unwrap_structs) {Check_Type(_val, T_DATA); _var = pgresult_get(_val);} else {Data_Get_Struct(_val, PGresult, _var);}
static VALUE spg_Sequel;
static VALUE spg_Blob;
@@ -620,12 +620,16 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
VALUE pg_value;
char type = SPG_YIELD_NORMAL;
+ if (!RTEST(rres)) {
+ return self;
+ }
+ GetPGresult(rres, res);
+
#ifdef SPG_ENCODING
int enc_index;
enc_index = enc_get_index(rres);
#endif
- GetPGresult(rres, res);
ntuples = PQntuples(res);
nfields = PQnfields(res);
if (nfields > SPG_MAX_FIELDS) {
View
2  sequel_pg.gemspec
@@ -1,6 +1,6 @@
SEQUEL_PG_GEMSPEC = Gem::Specification.new do |s|
s.name = 'sequel_pg'
- s.version = '1.6.11'
+ s.version = '1.6.12'
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"]
Please sign in to comment.
Something went wrong with that request. Please try again.