{"record":{"id":"30d6a7044ffd42bd","repo":"MuntashirAkon/AppManager","slug":"usage-s-port-token-am-jar-name-main-jar-name-app-id-user-id","errorCode":null,"errorMessage":"USAGE: %s <port> <token> <am_jar_name> <main_jar_name> <app_id> <user_id> <debug(1|0)> [extra_args...]\\n","messagePattern":"USAGE: (.+?) <port> <token> <am_jar_name> <main_jar_name> <app_id> <user_id> <debug\\(1\\|0\\)> \\[extra_args\\.\\.\\.\\]\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/main/cpp/run_server.c","lineNumber":74,"sourceCode":"    while ((n = read(fd_src, buf, sizeof(buf))) > 0) {\n        if (write(fd_dst, buf, n) != n) {\n            // Write failed\n            close(fd_src);\n            close(fd_dst);\n            unlink(dst);\n            return -1;\n        }\n    }\n\n    close(fd_src);\n    close(fd_dst);\n\n    return (n < 0) ? -1 : 0;\n}\n\nint main(int argc, char *argv[]) {\n    if (argc < 8) {\n        fprintf(stderr,\n                \"USAGE: %s <port> <token> <am_jar_name> <main_jar_name> <app_id> <user_id> <debug(1|0)> [extra_args...]\\n\",\n                argv[0]);\n        return 1;\n    }\n\n    const char *port = argv[1];\n    const char *token = argv[2];\n    const char *am_jar_name = argv[3];\n    const char *main_jar_name = argv[4];\n    const char *app_id = argv[5];\n    const char *user_id = argv[6];\n    const char *debug = argv[7];\n    const char *bgrun = \"1\";\n\n    // Validate Paths\n    if (!is_safe_string(am_jar_name) || !is_safe_string(main_jar_name) || !is_safe_string(app_id) ||\n        !is_safe_string(user_id)) {\n        fprintf(stderr, \"Error! Invalid characters in arguments.\\n\");","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/cpp/run_server.c#L56-L92","documentation":"The process was launched with fewer than the 8 mandatory arguments required by run_server (program name plus port, token, am_jar_name, main_jar_name, app_id, user_id, debug). The native server binary refuses to start without the full launch contract supplied by the caller (typically the Android app spawning it via exec).","triggerScenarios":"main() is invoked with argc < 8, i.e. one or more of the required positional arguments port/token/am_jar_name/main_jar_name/app_id/user_id/debug is missing, or extra_args contains values that shift nothing but required slots were never filled.","commonSituations":"The spawning Android code builds the exec argv array incorrectly (misses an argument or passes null); an updated binary added a new required parameter while the app-side launcher was not rebuilt; a manual shell test on /data/local/tmp omits arguments.","solutions":["Fix the launcher (Runtime.exec/ProcessBuilder or C wrapper) to pass all 7 arguments in order: port, token, am_jar_name, main_jar_name, app_id, user_id, debug","Add an argument-count check on the caller side before exec'ing the binary","Rebuild/redeploy both the native binary and the app so both sides agree on the argument contract"],"exampleFix":"// before\nProcess p = Runtime.getRuntime().exec(new String[]{\"su\",\"-c\",binary});\n// after\nProcess p = Runtime.getRuntime().exec(new String[]{\"su\",\"-c\",binary+\" \"+port+\" \"+token+\" \"+amJarName+\" \"+mainJarName+\" \"+appId+\" \"+userId+\" \"+(debug?1:0)});","handlingStrategy":"validation","validationCode":"String[] args = {port, token, amJar, mainJar, appId, userId, debug ? \"1\" : \"0\"};\nif (args.length < 7 || Arrays.stream(args).anyMatch(a -> a == null || a.isEmpty()))\n    throw new IllegalStateException(\"run_server requires 7 arguments\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the argument list in one shared constant/builder used by all launch sites","Log the full argv before exec to spot missing slots early","Add a smoke test that execs the binary with dummy args and asserts it passes the usage check"],"tags":["cli","native","argument-count"],"backgroundTag":"missing-cli-argument","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}