Skip to content

Commit 1665272

Browse files
author
David Viner
committed
adding segfault detection as proposed by Lenar Lõhmus [lenar@vision.ee]
--dviner
1 parent 4368b8e commit 1665272

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

ext/xslt/sablot.c

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,19 @@ static int scheme_getall(void *user_data, SablotHandle proc, const char *scheme,
745745
xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all,
746746
3, argv, &retval);
747747

748+
if(!retval) {
749+
/* return failure */
750+
return 1;
751+
}
752+
748753
/* Save the return value in the buffer (copying it) */
749754
*buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
750755
*byte_count = Z_STRLEN_P(retval);
751756

752757
/* Free return value */
753758
zval_ptr_dtor(&retval);
754-
759+
760+
/* return success */
755761
return 0;
756762
}
757763
/* }}} */
@@ -823,12 +829,22 @@ static int scheme_open(void *user_data, SablotHandle proc, const char *scheme,
823829
xslt_call_function("scheme open", XSLT_SCHEME(handle).open,
824830
3, argv, &retval);
825831

832+
if(!retval) {
833+
/* return failure */
834+
return 1;
835+
}
836+
826837
/* Return value is a resource pointer to an open file */
827838
*fd = Z_LVAL_P(retval);
828-
839+
829840
/* Free it all up */
830841
zval_ptr_dtor(&retval);
831842

843+
if(!*fd) {
844+
/* return failure - unsupported scheme */
845+
return SH_ERR_UNSUPPORTED_SCHEME;
846+
}
847+
832848
/* return success */
833849
return 0;
834850
}
@@ -867,6 +883,11 @@ static int scheme_get(void *user_data, SablotHandle proc, int fd, char *buffer,
867883
xslt_call_function("scheme get", XSLT_SCHEME(handle).get,
868884
3, argv, &retval);
869885

886+
if(!retval) {
887+
/* return failure */
888+
return 1;
889+
}
890+
870891
/* Returns the number of bytes read */
871892
*byte_count = Z_LVAL_P(retval);
872893

@@ -911,6 +932,11 @@ static int scheme_put(void *user_data, SablotHandle proc, int fd, const char *b
911932
xslt_call_function("scheme put", XSLT_SCHEME(handle).put,
912933
3, argv, &retval);
913934

935+
if(!retval) {
936+
/* return failure */
937+
return 1;
938+
}
939+
914940
/* The return value is the number of bytes written */
915941
*byte_count = Z_LVAL_P(retval);
916942

@@ -952,6 +978,11 @@ static int scheme_close(void *user_data, SablotHandle proc, int fd)
952978
xslt_call_function("scheme close", XSLT_SCHEME(handle).close,
953979
2, argv, &retval);
954980

981+
if(!retval) {
982+
/* return failure */
983+
return 1;
984+
}
985+
955986
/* Free everything up */
956987
zval_ptr_dtor(&retval);
957988

@@ -986,7 +1017,8 @@ static SAX_RETURN sax_startdoc(void *ctx, SablotHandle processor)
9861017
1, argv, &retval);
9871018

9881019
/* Cleanup */
989-
zval_ptr_dtor(&retval);
1020+
if(retval)
1021+
zval_ptr_dtor(&retval);
9901022
}
9911023
/* }}} */
9921024

@@ -1034,7 +1066,8 @@ static SAX_RETURN sax_startelement(void *ctx, SablotHandle processor,
10341066
3, argv, &retval);
10351067

10361068
/* Cleanup */
1037-
zval_ptr_dtor(&retval);
1069+
if(retval)
1070+
zval_ptr_dtor(&retval);
10381071
}
10391072
/* }}} */
10401073

@@ -1068,7 +1101,8 @@ static SAX_RETURN sax_endelement(void *ctx, SablotHandle processor, const char *
10681101
2, argv, &retval);
10691102

10701103
/* Cleanup */
1071-
zval_ptr_dtor(&retval);
1104+
if(retval)
1105+
zval_ptr_dtor(&retval);
10721106
}
10731107
/* }}} */
10741108

@@ -1107,7 +1141,8 @@ static SAX_RETURN sax_startnamespace(void *ctx, SablotHandle processor,
11071141
3, argv, &retval);
11081142

11091143
/* Cleanup */
1110-
zval_ptr_dtor(&retval);
1144+
if(retval)
1145+
zval_ptr_dtor(&retval);
11111146
}
11121147
/* }}} */
11131148

@@ -1141,7 +1176,8 @@ static SAX_RETURN sax_endnamespace(void *ctx, SablotHandle processor, const char
11411176
2, argv, &retval);
11421177

11431178
/* Cleanup */
1144-
zval_ptr_dtor(&retval);
1179+
if(retval)
1180+
zval_ptr_dtor(&retval);
11451181
}
11461182
/* }}} */
11471183

@@ -1175,7 +1211,8 @@ static SAX_RETURN sax_comment(void *ctx, SablotHandle processor, const char *con
11751211
2, argv, &retval);
11761212

11771213
/* Cleanup */
1178-
zval_ptr_dtor(&retval);
1214+
if(retval)
1215+
zval_ptr_dtor(&retval);
11791216
}
11801217
/* }}} */
11811218

@@ -1214,7 +1251,8 @@ static SAX_RETURN sax_pi(void *ctx, SablotHandle processor,
12141251
3, argv, &retval);
12151252

12161253
/* Cleanup */
1217-
zval_ptr_dtor(&retval);
1254+
if(retval)
1255+
zval_ptr_dtor(&retval);
12181256
}
12191257
/* }}} */
12201258

@@ -1250,7 +1288,8 @@ static SAX_RETURN sax_characters(void *ctx, SablotHandle processor,
12501288
2, argv, &retval);
12511289

12521290
/* Cleanup */
1253-
zval_ptr_dtor(&retval);
1291+
if(retval)
1292+
zval_ptr_dtor(&retval);
12541293
}
12551294
/* }}} */
12561295

@@ -1281,7 +1320,8 @@ static SAX_RETURN sax_enddoc(void *ctx, SablotHandle processor)
12811320
1, argv, &retval);
12821321

12831322
/* Cleanup */
1284-
zval_ptr_dtor(&retval);
1323+
if(retval)
1324+
zval_ptr_dtor(&retval);
12851325
}
12861326
/* }}} */
12871327

@@ -1499,7 +1539,8 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M
14991539
4, argv, &retval);
15001540

15011541
/* Free up */
1502-
zval_ptr_dtor(&retval);
1542+
if(retval)
1543+
zval_ptr_dtor(&retval);
15031544
}
15041545
else {
15051546
char *errmsg = NULL; /* Error message */

ext/xslt/xslt.dsp

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)