| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
|
| #include <unistd.h> |
| 7 |
|
| |
| 8 |
|
| MODULE = Unix::Pledge PACKAGE = Unix::Pledge |
| 9 |
|
| |
| 10 |
|
| void |
| 11 |
|
| pledge(promises, ...) |
| 12 |
|
| const char *promises |
| 13 |
|
| PROTOTYPE: $;$ |
| 14 |
|
| INIT: |
| 15 |
|
| // Check that if 2nd param provided it is an array ref |
| 16 |
0 |
▶ | if (items > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) { |
0 |
0 |
0 |
|
| 17 |
0 |
| SvGETMAGIC(ST(1)); |
| 18 |
0 |
▶ | if ((!SvROK(ST(1))) || (SvTYPE(SvRV(ST(1))) != SVt_PVAV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!SvROK(ST(1))) || (SvTYPE(SvRV(ST(1))) != SVt_PVAV)) |
0 |
0 |
0 |
| if ((!SvROK(ST(1))) || (SvTYPE(SvRV(ST(1))) != SVt_PVAV)) |
0 |
0 |
0 |
|
| 19 |
|
| { |
| 20 |
0 |
| croak("unable to pledge: %s", "whitelist parameter must be an array ref"); |
| 21 |
|
| } |
| 22 |
|
| } |
| 23 |
|
| CODE: |
| 24 |
0 |
| SSize_t numpaths = 0, n; |
| 25 |
|
| |
| 26 |
|
| // whitelist provided |
| 27 |
0 |
▶ | if (items > 1 && (numpaths = av_top_index((AV *)SvRV(ST(1))) >= 0)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (items > 1 && (numpaths = av_top_index((AV *)SvRV(ST(1))) >= 0)) { |
0 |
0 |
0 |
| if (items > 1 && (numpaths = av_top_index((AV *)SvRV(ST(1))) >= 0)) { |
0 |
0 |
0 |
|
| 28 |
|
| |
| 29 |
0 |
| const char *wpaths[numpaths+1]; |
| 30 |
|
| |
| 31 |
0 |
▶ | for (n = 0; n < numpaths; n++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (n = 0; n < numpaths; n++) { |
0 |
0 |
0 |
|
| 32 |
|
| STRLEN l; |
| 33 |
0 |
| wpaths[n] = SvPV(*av_fetch((AV *)SvRV(ST(1)), n, 0), l); |
| 34 |
|
| } |
| 35 |
0 |
| wpaths[numpaths] = NULL; |
| 36 |
|
| |
| 37 |
0 |
▶ | if (pledge(promises, wpaths) == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pledge(promises, wpaths) == -1) { |
0 |
0 |
0 |
|
| 38 |
0 |
| croak("unable to pledge: %s", strerror(errno)); |
| 39 |
|
| } |
| 40 |
|
| } |
| 41 |
|
| // no whitelist provided |
| 42 |
|
| else { |
| 43 |
0 |
▶ | if (pledge(promises, NULL) == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pledge(promises, NULL) == -1) { |
0 |
0 |
0 |
|
| 44 |
0 |
| croak("unable to pledge: %s", strerror(errno)); |
| 45 |
|
| } |
| 46 |
|
| } |