summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2013-06-04 21:10:28 +0200
committerAndroid Git Automerger <android-git-automerger@android.com>2013-06-04 21:10:28 +0200
commit8cd12112e444e01163526fe6ab237f6164b0018b (patch)
treec7223f8e8a1256dc0e3c27665138cd3c0d740c54
parentrecovery: save logs from the last few invocations of recovery (diff)
parentMerge "Fix the potential segmentation fault" (diff)
downloadandroid_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar.gz
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar.bz2
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar.lz
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar.xz
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.tar.zst
android_bootable_recovery-8cd12112e444e01163526fe6ab237f6164b0018b.zip
Diffstat (limited to '')
-rw-r--r--recovery.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 840e63c42..c82844d25 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -200,6 +200,7 @@ get_args(int *argc, char ***argv) {
if (*argc <= 1) {
FILE *fp = fopen_path(COMMAND_FILE, "r");
if (fp != NULL) {
+ char *token;
char *argv0 = (*argv)[0];
*argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
(*argv)[0] = argv0; // use the same program name
@@ -207,7 +208,12 @@ get_args(int *argc, char ***argv) {
char buf[MAX_ARG_LENGTH];
for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
if (!fgets(buf, sizeof(buf), fp)) break;
- (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline.
+ token = strtok(buf, "\r\n");
+ if (token != NULL) {
+ (*argv)[*argc] = strdup(token); // Strip newline.
+ } else {
+ --*argc;
+ }
}
check_and_fclose(fp, COMMAND_FILE);