Repository navigation
fix(android): quote package names before they reach adb shell - #471
Conversation
adb joins everything after `shell` with spaces and hands the result to the device's sh, so a package name such as 'com.example; touch /sdcard/x' ran a second command as the shell user. apps launch, terminate, path and clear now send their arguments pre-quoted, the way the fs commands already do.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: mobile-next/mobilecli/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughThe Android device code adds shell argument quoting and uses it for app-related commands. Unit and device tests check that package names containing shell syntax do not execute an appended command. ChangesAndroid shell argument quoting
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change quotes package names before device-shell execution without changing normal app-command behavior. No actionable merge-blocking risk remains after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🧪 Generate unit tests (beta)
🛠️ Fix failing CI checks 💡
Comment |
Summary
apps launch,apps terminate,apps pathandapps clearpassed the package name toadb shellunquoted. adb joins everything aftershellwith spaces and hands the result to the device'ssh, so a package name carrying shell syntax ran a second command as the shell user:Changes
devices/android.go: newadbShellArgs/runAdbShellhelper that quotes every argument withshellescape.QuoteCommand(the same quoting thefscommands already use), used by the calls that carry a caller-supplied package name:resolve-activity,set-app-locales,am start -n,am force-stop,pm path,pm dump,pm clear.no launcher activity found for …,dataDir not found for package …) and nothing extra runs on the device.mobilecli urlhas the same root cause and is fixed separately, together with the&truncation it also causes. That PR adds the same helper with identical text, so the two merge in either order.Testing
test/android.spec.ts("a package name carrying a shell command"), one per subcommand: each smuggles atouchinto the package name and asserts the file does not appear in/sdcard/Download. All four failed before the fix and pass after.Test_adbShellArgs_keepsAPackageNameFromBecomingASecondCommand.go test ./... -racepasses;golangci-lint run --new-from-rev=mainreports 0 issues.Related Issues
None
Summary by CodeRabbit