Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35c94f3c authored by Felipe Leme's avatar Felipe Leme
Browse files

Created constant for maximun number of args.

BUG: 26379932
Change-Id: I839f6e3f90010ee35bc5d40e96218e9c95afdf4e
parent 5885800d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -278,11 +278,12 @@ static void _run_dumpsys(const std::string& title, RootMode root_mode, int timeo

    std::string timeout_string = std::to_string(timeout_seconds);

    const char *dumpsys_args[ARG_MAX] = { "/system/bin/dumpsys", "-t", timeout_string.c_str()};
    const char *dumpsys_args[MAX_ARGS_ARRAY_SIZE] =
        { "/system/bin/dumpsys", "-t", timeout_string.c_str()};

    int index = 3; // 'dumpsys' '-t' 'TIMEOUT'
    for (const std::string& arg : args) {
        if (index > ARG_MAX - 2) {
        if (index > MAX_ARGS_ARRAY_SIZE - 2) {
            MYLOGE("Too many arguments for '%s': %d\n", title.c_str(), (int) args.size());
            return;
        }
+5 −0
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@

#define SU_PATH "/system/xbin/su"

// Workaround for const char *args[MAX_ARGS_ARRAY_SIZE] variables until they're converted to
// std::vector<std::string>
#define MAX_ARGS_ARRAY_SIZE 1000


#ifdef __cplusplus
extern "C" {
#endif
+5 −5
Original line number Diff line number Diff line
@@ -655,7 +655,7 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...
    DurationReporter duration_reporter(title);
    fflush(stdout);

    const char *args[ARG_MAX] = {command};
    const char *args[MAX_ARGS_ARRAY_SIZE] = {command};
    size_t arg;
    va_list ap;
    va_start(ap, command);
@@ -696,7 +696,7 @@ int run_command_as_shell(const char *title, int timeout_seconds, const char *com
    DurationReporter duration_reporter(title);
    fflush(stdout);

    const char *args[ARG_MAX] = {command};
    const char *args[MAX_ARGS_ARRAY_SIZE] = {command};
    size_t arg;
    va_list ap;
    va_start(ap, command);
@@ -888,11 +888,11 @@ void send_broadcast(const std::string& action, const std::vector<std::string>& a
        MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
        return;
    }
    const char *am_args[ARG_MAX] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
    const char *am_args[MAX_ARGS_ARRAY_SIZE] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
                                     action.c_str() };
    size_t am_index = 5; // Starts at the index of last initial value above.
    for (const std::string& arg : args) {
        if (am_index > ARG_MAX - 2) {
        if (am_index > MAX_ARGS_ARRAY_SIZE - 2) {
            MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
            return;
        }
@@ -1416,7 +1416,7 @@ void format_args(const char* command, const char *args[], std::string *string) {
    if (args[1] == nullptr) return;
    string->append(" ");

    for (int arg = 1; arg <= 1000; ++arg) {
    for (int arg = 1; arg <= MAX_ARGS_ARRAY_SIZE; ++arg) {
        if (args[arg] == nullptr) return;
        string->append(args[arg]);
        if (args[arg+1] != nullptr) {