[867] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r856 - branches/barnowl_sqlite/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:10:34 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Sat, 12 Jan 2008 19:06:35 -0500 (EST)

Author: nelhage
Date: 2008-01-12 19:06:34 -0500 (Sat, 12 Jan 2008)
New Revision: 856

Modified:
   branches/barnowl_sqlite/owl/message.c
Log:
Make it harder for perl to crash barnowl

Modified: branches/barnowl_sqlite/owl/message.c
===================================================================
--- branches/barnowl_sqlite/owl/message.c	2008-01-13 00:05:58 UTC (rev 855)
+++ branches/barnowl_sqlite/owl/message.c	2008-01-13 00:06:34 UTC (rev 856)
@@ -28,7 +28,7 @@
   XPUSHs(sv_2mortal(newSVpv("BarnOwl::Message", 0)));
   PUTBACK;
 
-  count = call_method("new", G_SCALAR|G_EVAL|G_KEEPERR);
+  count = call_method("new", G_SCALAR|G_EVAL);
 
   SPAGAIN;
 
@@ -989,15 +989,19 @@
 owl_fmtext_cache *owl_message_get_fmtext_cache(owl_message *m)
 {
   SV *fmtext = owl_message_get_attribute_internal(m, "__fmtext");
-  if(fmtext && SvROK(fmtext))
-    return INT2PTR(owl_fmtext_cache*, SvIV(SvRV(fmtext)));
+  if(fmtext && SvROK(fmtext)) {
+    int fm_which = SvIV(SvRV(fmtext));
+    if(fm_which >= 0 && fm_which < OWL_FMTEXT_CACHE_SIZE) {
+      return fmtext_cache + fm_which;
+    }
+  }
   return NULL;
 }
 
 void owl_message_set_fmtext_cache(owl_message *m, owl_fmtext_cache *fm)
 {
   SV *fmtext = newSV(0);
-  sv_setref_pv(fmtext, Nullch, fm);
+  sv_setref_iv(fmtext, Nullch, (fm - fmtext_cache));
   HV *hash = (HV*)SvRV((SV*)m);
   hv_store(hash, "__fmtext", strlen("__fmtext"), fmtext, 0);
 }
@@ -1068,10 +1072,6 @@
 }
 
 void owl_message_attributes_tofmtext(owl_message *m, owl_fmtext *fm) {
-  int i, j;
-  owl_pair *p;
-  char *buff;
-
   owl_fmtext_init_null(fm);
 
   char *text = owl_perlconfig_message_call_method(m, "__format_attributes", 0, NULL);


home help back first fref pref prev next nref lref last post