MuntashirAkon/AppManager · error

Error! Buffer overflow on args_buf.\n

Error message

Error! Buffer overflow on args_buf.\n

What it means

The composed argument string "path:<port>,token:<token>,app:<app_id>,bgrun:<bgrun>,debug:<debug>" exceeded the 2048-byte args_buf, so snprintf truncated it and the binary aborts (cleaning up the copied am.jar via unlink).

Source

Thrown at app/src/main/cpp/run_server.c:189

            resolved_main_jar_path = main_jar_fallbacks[i];
            break;
        }
    }
    if (resolved_main_jar_path == NULL) {
        fprintf(stderr, "Error! %s could not be found or copied.\n", main_jar_name);
        return 1;
    }
    // Fix ownership
    if (chown(main_jar_path, uid, gid) != 0) {
        fprintf(stderr, "Warning: chown failed: %s\n", strerror(errno));
        // Although it failed, still proceed
    }

    // Build argument for am.jar
    char args_buf[2048];
    if (snprintf(args_buf, sizeof(args_buf), "path:%s,token:%s,app:%s,bgrun:%s,debug:%s",
                 port, token, app_id, bgrun, debug) >= sizeof(args_buf)) {
        fprintf(stderr, "Error! Buffer overflow on args_buf.\n");
        unlink(exec_jar_path);
        return 1;
    }

    printf("Resolved Jar path: %s\n", resolved_am_jar_path);
    printf("Args: %s\n", args_buf);

    // Execute app_process
    if (setenv("CLASSPATH", exec_jar_path, 1) != 0) {
        fprintf(stderr, "Error setting CLASSPATH\n");
        unlink(exec_jar_path);
        return 1;
    }

    int extra_args_count = argc - 8;
    int exec_argc = 6 + extra_args_count;
    char **exec_argv = malloc(sizeof(char *) * exec_argc);
    if (!exec_argv) {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Shorten the token/app_id values on the caller side (tokens should be compact)
  2. Increase args_buf to e.g. 4096 or 8192 in run_server.c and rebuild
  3. Validate combined argument length in the app before exec and reject oversized values

Example fix

// before
char args_buf[2048];
// after
char args_buf[8192];
Defensive patterns

Strategy: validation

Validate before calling

String argsStr = String.format("path:%s,token:%s,app:%s,bgrun:1,debug:%s",
        port, token, appId, debug);
if (argsStr.length() >= 2048)
    throw new IllegalArgumentException("combined run_server arguments exceed 2048 bytes; shorten token/app_id");

Prevention

When it happens

Trigger: Combined lengths of port + token + app_id plus fixed format text reach 2048 bytes — typically a very long token or app_id.

Common situations: Long JWT/opaque tokens passed as <token>; verbose app_ids; future fields appended to the format string without growing the buffer; callers embedding extra data into token.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/a15e79ae6739927a. Report an issue: GitHub.