{"record":{"id":"0fb8c5d5470ff9a7","repo":"MuntashirAkon/AppManager","slug":"error-buffer-overflow-on-main-jar-path-n","errorCode":null,"errorMessage":"Error! Buffer overflow on main_jar_path.\\n","messagePattern":"Error! Buffer overflow on main_jar_path\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/main/cpp/run_server.c","lineNumber":114,"sourceCode":"    // Validate debug and bgrun\n    if ((strcmp(debug, \"0\") != 0 && strcmp(debug, \"1\") != 0)) {\n        fprintf(stderr, \"Error! debug must be either 0 or 1.\\n\");\n        return 1;\n    }\n\n    // /data/local/tmp/am.jar\n    char exec_jar_path[512];\n    if (snprintf(exec_jar_path, sizeof(exec_jar_path), \"%s/%s\", TMP_PATH, am_jar_name) >=\n        sizeof(exec_jar_path)) {\n        fprintf(stderr, \"Error! Buffer overflow on exec_jar_path.\\n\");\n        return 1;\n    }\n\n    // /data/local/tmp/main.jar\n    char main_jar_path[512];\n    if (snprintf(main_jar_path, sizeof(main_jar_path), \"%s/%s\", TMP_PATH, main_jar_name) >=\n        sizeof(main_jar_path)) {\n        fprintf(stderr, \"Error! Buffer overflow on main_jar_path.\\n\");\n        return 1;\n    }\n\n    // Prioritized list of fallback source paths\n    char am_jar_fallbacks[4][512];\n    snprintf(am_jar_fallbacks[0], sizeof(am_jar_fallbacks[0]), \"/sdcard/Android/data/%s/cache/%s\",\n             app_id,\n             am_jar_name);\n    snprintf(am_jar_fallbacks[1], sizeof(am_jar_fallbacks[1]),\n             \"/storage/emulated/%s/Android/data/%s/cache/%s\",\n             user_id, app_id, am_jar_name);\n    snprintf(am_jar_fallbacks[2], sizeof(am_jar_fallbacks[2]), \"/sdcard/AppManager/%s\",\n             am_jar_name);\n    snprintf(am_jar_fallbacks[3], sizeof(am_jar_fallbacks[3]), \"/storage/emulated/%s/AppManager/%s\",\n             user_id,\n             am_jar_name);\n\n    char main_jar_fallbacks[4][512];","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/cpp/run_server.c#L96-L132","documentation":"Guard after snprintf in main(): building the path for the main jar (TMP_PATH plus main_jar_name) overflowed its 512-byte main_jar_path buffer. Like the exec_jar_path check, it aborts early to avoid using a truncated or non-terminating path; the faulting input is an over-long main_jar_name argument.","triggerScenarios":"len(TMP_PATH) + 1 + strlen(main_jar_name) >= 512.","commonSituations":"Overly long main jar filename or a long custom TMP_PATH; directory components embedded in main_jar_name pushing the length over the limit.","solutions":["Use a shorter main_jar_name","Bump the buffer to PATH_MAX in run_server.c and rebuild","Enforce a filename length limit (e.g. <= 256 chars) in the app before launching"],"exampleFix":"// before\nchar main_jar_path[512];\n// after\nchar main_jar_path[PATH_MAX];","handlingStrategy":"validation","validationCode":"String path = TMP_PATH + \"/\" + mainJarName;\nif (path.length() >= 512)\n    throw new IllegalArgumentException(\"main_jar_name too long (path would exceed 512 bytes)\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enforce a filename length limit before staging files","Keep TMP_PATH short","Prefer fixed short names like \"main.jar\""],"tags":["buffer-overflow","path-length","native"],"backgroundTag":"value-out-of-range","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"}