Skip to content

Commit

Permalink
[hack] adding a test file about variadic arguments
Browse files Browse the repository at this point in the history
Summary:
Now that Textual is able to translate variadic arguments to SIL,
we need to tell Pulse how to analyse them. We set the playground with this test.

Reviewed By: vsiles

Differential Revision:
D50120795

Privacy Context Container: L1208441

fbshipit-source-id: d47704c3e4ee66666afabf44030ae970164ee816
  • Loading branch information
davidpichardie authored and facebook-github-bot committed Oct 11, 2023
1 parent 067f646 commit 16c3802
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions infer/tests/codetoanalyze/hack/pulse/variadic.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

namespace DictTests;

class Variadic {

public static function variadicArgInSink(int $i, int ...$args) : void {
foreach ($args as $arg) {
\Level1\taintSink($arg);
}
}

public static function variadicArg0InSink(int $i, int ...$args) : void {
\Level1\taintSink($args[0]);
}

public static function callVariadic(int ...$args) : void {
self::variadicArgInSink(0, ...$args);
}

public static function FN_callVariadicWith2ArgsBad(int $i) : void {
self::variadicArgInSink(0, \Level1\taintSource());
}

public static function callVariadicWith2ArgsOk(int $i) : void {
self::variadicArgInSink(\Level1\taintSource(), 0);
}

public static function FN_callVariadicWith3ArgsBad() : void {
self::variadicArgInSink(0, 0, \Level1\taintSource());
}

public static function FN_callVariadicWith3ArgsBisBad() : void {
self::variadicArgInSink(0, \Level1\taintSource(), 0);
}

public static function FN_transitiveCallVariadicWith2ArgsBad(int $i) : void {
self::callVariadic(\Level1\taintSource());
}

public static function FN_transitiveCallVariadicWith3ArgsBad() : void {
self::callVariadic(0, \Level1\taintSource());
}

public static function FN_transitiveCallVariadicWith3ArgsBisBad() : void {
self::callVariadic(\Level1\taintSource(), 0);
}

public static function FN_callVariadicArg0InSinkBad() : void {
self::variadicArg0InSink(0, \Level1\taintSource());
}

public static function callVariadicArg0InSinkOk() : void {
self::variadicArg0InSink(0, 0, \Level1\taintSource());
}

public static function callVariadicArg0InSinkBisOk() : void {
self::variadicArg0InSink(\Level1\taintSource());
}
}

0 comments on commit 16c3802

Please sign in to comment.