1

It's not the first time I get this strange NOTICE when adding perl functions in Postgresql :

NOTICE: elseif should be elsif at line 11.

This happens at CREATE FUNCTION as well as when using the function. Of course I tried to change with elsif but then it fails with syntax error.

Any advice would be appreciated (even if I can cope with that NOTICE)

This is my code:

CREATE FUNCTION hds_updatewebservers_products(character varying) 
   RETURNS boolean 
AS 
$_$ 
   my $product_ref = @_[0]; 
   # Launch update 
   $checkexitcode = system ("sudo -u dbliveud /home/dbliveud/scripts/maj/launch-all.sh " . $product_ref . " "); 
   if ($checkexitcode > 0) { 
     # Error while updating 
     return false; 
   } elseif { 
     # Ok update done 
     return true; 
   } 
$_$ 
LANGUAGE plperlu STRICT;
0

1 Answer 1

1

I can't reproduce your error, it works fine on my PostgreSQL 9.5 on Linux. What version and platform are you running?

Note that your function can be exploited really badly, e.g.

select hds_updatewebservers_products('1; rm -rf /')

Why are you using elseif? Why not just else? See perl's documentation on elseif

Finally, you can simply (and elegantly):

CREATE FUNCTION hds_updatewebservers_products(character varying) RETURNS boolean AS $_$
  my $product_ref = @_[0]; # Launch update

  $product_ref =~ /^\w$/ or die 'Invalid product ref!'; # added for safety

  $checkexitcode = system ("sudo -u dbliveud /home/dbliveud/scripts/maj/launch-all.sh " . $product_ref . " ");

  # positive value means error while updating, otherwise update done OK
  return !($checkexitcode > 0);
$_$ LANGUAGE plperlu STRICT;
3
  • Firstly, yes you're right : why am I using elseif instead of else ? Good question. That's the first problem/error to be corrected. Jun 8, 2016 at 13:12
  • Secondly, about security, it's a 100% internal function that is used based on internal data, imported from another internal database, therefore no risk. But I also like to secure everything ("better be safe than sorry") and I will secure my perl function based on your advice : a great thank you for your help ! Jun 8, 2016 at 13:15
  • P. S. The Postgresql version is 8.3.17 with perl 5.10.0 (yes I know a little old but it works well. Linux stability means sometimes older versions in production) Jun 8, 2016 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.