Issues (7)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/prim.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 123.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * @file
5
 * Primitive functions.
6
 *
7
 * Overall implementation notes:
8
 *  - Exceptions are closer to MDL's <ERROR> behavior and are used instead of
9
 *    trigger_error().
10
 */
11
12
namespace Itafroma\Zork;
13
14
use Itafroma\Zork\Exception\ConstantAlreadyDefinedException;
15
use Itafroma\Zork\Exception\FlagwordException;
16
use Itafroma\Zork\Exception\PsetgDuplicateException;
17
use Itafroma\Zork\Exception\SlotNameAlreadyUsedException;
18
use Itafroma\Zork\Struc\StrucInterface;
19
use \BadFunctionCallException;
20
21
/**
22
 * Defines a global constant, throwing an exception if it's already set.
23
 *
24
 * Effectively acts like a declare(), but elevates PHP's built-in E_NOTICE on
25
 * redefining constants to an exception.
26
 *
27
 * @param string $foo The constant name to set.
28
 * @param mixed  $bar The value to set $foo to.
29
 * @throws Itafroma\Zork\Exception\ConstantAlreadyDefinedException
30
 */
31
function msetg($foo, $bar) {
32 3
    if (gassigned($foo) && $bar != gval($foo)) {
33 1
        throw new ConstantAlreadyDefinedException();
34
    }
35
36 3
    return setg($foo, $bar);
37
}
38
39
/**
40
 * Sets a global variable and adds its value to the global "pure_list" array.
41
 *
42
 * @param string $foo The global variable to set.
43
 * @param mixed  $bar The value to set $foo to.
44
 * @return mixed The value of $bar.
45
 * @throws Itafroma\Zork\Exception\PsetgDuplicateException
46
 */
47
function psetg($foo, $bar) {
48 3
    setg($foo, $bar);
49 3
    $pl = gassigned('PURE-LIST') ? gval('PURE-LIST') : setg('PURE-LIST', []);
50
51 3
    if (!in_array($foo, $pl)) {
52 3
        array_unshift($pl, $foo);
53 3
        setg('PURE-LIST', $pl);
54 3
    }
55 2
    elseif (gassigned('PURE-CAREFUL') && gval('PURE-CAREFUL')) {
56 1
        throw new PsetgDuplicateException();
57
    }
58
59 3
    return $bar;
60
}
61
62
/**
63
 * Creates a flag/bit field.
64
 *
65
 * In the original source, there's a hard limit of 35 flags that can be added to
66
 * the flag field, presumably done for memory conservation.
67
 *
68
 * @param string ... $fs A list of flags to add.
69
 * @return int The number of flags added.
70
 * @throws Itafroma\Zork\Exception\FlagwordException
71
 */
72
function flagword(...$fs) {
73 3
    $container = ServiceContainer::getContainer();
74 3
    $oblists = $container->get('oblists');
75 3
    $tot = 1;
76 3
    $cnt = 1;
77
78
    // Given <FLAGWORD>'s usage in the rest of the original source, this could
79
    // be simplified to a simple foreach loop. The use of array_walk_recursive()
80
    // here is to emulate the use of MDL's <MAPF> SUBR in the original source.
81
    array_walk_recursive($fs, function($f) use ($oblists, &$tot, &$cnt) {
82
        // It's unknown what the GROUP-GLUE symbol is in the oblist. It appears
83
        // to be always empty.
84 3
        if (is_scalar($f) && !lookup('GROUP-GLUE', $oblists->get('INITIAL'))) {
85 2
            msetg($f, $tot);
86 2
        }
87
88 3
        $tot *= 2;
89
90
        // This appears to be a bug in the original source: the intention seems
91
        // to be to allow bit fields with up to 36 flags, but because the size
92
        // is incremented and checked after the last value is set, it only
93
        // allows 35 flags.
94 3
        $cnt++;
95 3
        if ($cnt > 36) {
96 1
            throw new FlagwordException();
97
        }
98 3
    });
99
100
    // Also a bug in the original source: since count is incremented after the
101
    // last value is added, the reported number of flags added is off by one.
102 2
    return $cnt;
103
}
104
105
/**
106
 * Generates a new structure.
107
 *
108
 * This function is intentionally left unimplemented. The purpose of it was to
109
 * emulate C's struct language feature. In PHP, struct emulation is done through
110
 * simple class declarations using public properties.
111
 *
112
 * @param string    $nam  The name of the structure.
113
 * @param string    $prim The underlying type of the structure.
114
 * @param mixed ... $elem A series of elements defining the structure,
115
 *                        alternating between the element name and the element
116
 *                        type.
117
 * @throws \BadFunctionCallException
118
 */
119
function newstruc($nam, $prim, ...$elem) {
0 ignored issues
show
The parameter $nam is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $prim is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $elem is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120 1
    throw new BadFunctionCallException('newstruc() has been removed: implement Itafroma\Zork\Struc\StrucInterface instead.');
121
}
122
123
setg('SLOTS', []);
124
125
/**
126
 * "Define a funny slot in an object." (sic)
127
 *
128
 * Essentially adds arbitrary named properties to objects. Not sure why they're
129
 * called "funny slots" yet.
130
 *
131
 * Usage:
132
 *  - Create: make_slot('foo', 'default value');
133
 *  - Read: $GLOBALS['zork']['foo']($object);
134
 *  - Update: $GLOBALS['zork']['foo']($object, 'new value');
135
 *
136
 * @param string $name The name of the slot to define.
137
 * @param mixed  $def  The default value of the slot defined.
138
 * @throws Itafroma\Zork|Exception\SlotNameAlreadyUsedException;
139
 */
140
function make_slot($name, $def) {
141
    // Slot names can only be used once globally.
142
    // REDEFINE is apparently a local variable in the original <DEFINE> and is
143
    // never bound.
144 4
    if (!gassigned($name) || !empty($redefine)) {
145 3
        $slots = gval('SLOTS');
146
        $slots[$name] = function (StrucInterface $obj, $val = null) use ($name, $def) {
147 2
            if (isset($val)) {
148 2
                return oput($obj, $name, $val);
149
            }
150
151 1
            return oget($obj, $name) ?: $def;
152
        };
153
154 3
        return setg('SLOTS', $slots);
155
    }
156
157 1
    throw new SlotNameAlreadyUsedException("$name already used.");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $name instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
158
}
159