From 87b8584d6acc50751dffd81d8bb187d3ad73462c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 14 Nov 2013 15:45:23 +0000 Subject: [PATCH] perl: Give error instead of crashing if optarg is not an array reference. $g->add_drive ("", server => 1); would segfault. Now it gives a nice error instead: array reference expected for 'server' argument at [line] (cherry picked from commit c032130226bdca539b8ac34ce622e5cd9a71c152) --- generator/perl.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generator/perl.ml b/generator/perl.ml index 1acd782..9b7c25a 100644 --- a/generator/perl.ml +++ b/generator/perl.ml @@ -464,10 +464,13 @@ PREINIT: | OStringList _ -> pr " size_t i, len;\n"; pr " char **r;\n"; + pr " SV *arg;\n"; pr " AV *av;\n"; pr " SV **svp;\n"; pr "\n"; - pr " /* XXX More checking required here. */\n"; + pr " arg = ST (items_i+1);\n"; + pr " if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV)\n"; + pr " croak (\"array reference expected for '%%s' argument\", \"%s\");\n" n; pr " av = (AV *) SvRV (ST (items_i+1));\n"; pr "\n"; pr " /* Note av_len returns index of final element. */\n"; -- 1.8.3.1