diff options
Diffstat (limited to 'updater')
-rw-r--r-- | updater/Android.mk | 24 | ||||
-rw-r--r-- | updater/blockimg.cpp (renamed from updater/blockimg.c) | 117 | ||||
-rw-r--r-- | updater/install.cpp (renamed from updater/install.c) | 179 | ||||
-rw-r--r-- | updater/updater.cpp (renamed from updater/updater.c) | 2 |
4 files changed, 195 insertions, 127 deletions
diff --git a/updater/Android.mk b/updater/Android.mk index ff02a33b0..82fa7e265 100644 --- a/updater/Android.mk +++ b/updater/Android.mk @@ -1,11 +1,23 @@ # Copyright 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. LOCAL_PATH := $(call my-dir) updater_src_files := \ - install.c \ - blockimg.c \ - updater.c + install.cpp \ + blockimg.cpp \ + updater.cpp # # Build a statically-linked binary to include in OTA packages @@ -17,6 +29,8 @@ include $(CLEAR_VARS) # needed only for OTA packages.) LOCAL_MODULE_TAGS := eng +LOCAL_CLANG := true + LOCAL_SRC_FILES := $(updater_src_files) ifeq ($(TARGET_USERIMAGES_USE_EXT4), true) @@ -30,9 +44,9 @@ LOCAL_STATIC_LIBRARIES += \ endif LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UPDATER_LIBS) $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS) -LOCAL_STATIC_LIBRARIES += libapplypatch libedify libmtdutils libminzip libz +LOCAL_STATIC_LIBRARIES += libapplypatch libbase libedify libmtdutils libminzip libz LOCAL_STATIC_LIBRARIES += libmincrypt libbz -LOCAL_STATIC_LIBRARIES += libcutils liblog libstdc++ libc +LOCAL_STATIC_LIBRARIES += libcutils liblog libc LOCAL_STATIC_LIBRARIES += libselinux tune2fs_static_libraries := \ libext2_com_err \ diff --git a/updater/blockimg.c b/updater/blockimg.cpp index b006d10c5..a7821f362 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.cpp @@ -20,6 +20,7 @@ #include <fcntl.h> #include <inttypes.h> #include <libgen.h> +#include <linux/fs.h> #include <pthread.h> #include <stdarg.h> #include <stdio.h> @@ -45,10 +46,6 @@ // erase to mean fill the region with zeroes. #define DEBUG_ERASE 0 -#ifndef BLKDISCARD -#define BLKDISCARD _IO(0x12,119) -#endif - #define STASH_DIRECTORY_BASE "/cache/recovery" #define STASH_DIRECTORY_MODE 0700 #define STASH_FILE_MODE 0600 @@ -61,30 +58,91 @@ typedef struct { int pos[0]; } RangeSet; +#define RANGESET_MAX_POINTS \ + ((int)((INT_MAX / sizeof(int)) - sizeof(RangeSet))) + static RangeSet* parse_range(char* text) { char* save; + char* token; int num; - num = strtol(strtok_r(text, ",", &save), NULL, 0); + long int val; + RangeSet* out = NULL; + size_t bufsize; - RangeSet* out = malloc(sizeof(RangeSet) + num * sizeof(int)); - if (out == NULL) { - fprintf(stderr, "failed to allocate range of %zu bytes\n", - sizeof(RangeSet) + num * sizeof(int)); - exit(1); + if (!text) { + goto err; } + + token = strtok_r(text, ",", &save); + + if (!token) { + goto err; + } + + val = strtol(token, NULL, 0); + + if (val < 2 || val > RANGESET_MAX_POINTS) { + goto err; + } else if (val % 2) { + goto err; // must be even + } + + num = (int) val; + bufsize = sizeof(RangeSet) + num * sizeof(int); + + out = reinterpret_cast<RangeSet*>(malloc(bufsize)); + + if (!out) { + fprintf(stderr, "failed to allocate range of %zu bytes\n", bufsize); + goto err; + } + out->count = num / 2; out->size = 0; - int i; - for (i = 0; i < num; ++i) { - out->pos[i] = strtol(strtok_r(NULL, ",", &save), NULL, 0); - if (i%2) { + + for (int i = 0; i < num; ++i) { + token = strtok_r(NULL, ",", &save); + + if (!token) { + goto err; + } + + val = strtol(token, NULL, 0); + + if (val < 0 || val > INT_MAX) { + goto err; + } + + out->pos[i] = (int) val; + + if (i % 2) { + if (out->pos[i - 1] >= out->pos[i]) { + goto err; // empty or negative range + } + + if (out->size > INT_MAX - out->pos[i]) { + goto err; // overflow + } + out->size += out->pos[i]; } else { + if (out->size < 0) { + goto err; + } + out->size -= out->pos[i]; } } + if (out->size <= 0) { + goto err; + } + return out; + +err: + fprintf(stderr, "failed to parse range '%s'\n", text ? text : "NULL"); + exit(1); } static int range_overlaps(RangeSet* r1, RangeSet* r2) { @@ -135,11 +193,6 @@ static int write_all(int fd, const uint8_t* data, size_t size) { written += w; } - if (fsync(fd) == -1) { - fprintf(stderr, "fsync failed: %s\n", strerror(errno)); - return -1; - } - return 0; } @@ -417,7 +470,7 @@ static char* GetStashFileName(const char* base, const char* id, const char* post } len = strlen(STASH_DIRECTORY_BASE) + 1 + strlen(base) + 1 + strlen(id) + strlen(postfix) + 1; - fn = malloc(len); + fn = reinterpret_cast<char*>(malloc(len)); if (fn == NULL) { fprintf(stderr, "failed to malloc %d bytes for fn\n", len); @@ -468,7 +521,7 @@ static void EnumerateStash(const char* dirname, StashCallback callback, void* da } len = strlen(dirname) + 1 + strlen(item->d_name) + 1; - fn = malloc(len); + fn = reinterpret_cast<char*>(malloc(len)); if (fn == NULL) { fprintf(stderr, "failed to malloc %d bytes for fn\n", len); @@ -588,7 +641,8 @@ static int LoadStash(const char* base, const char* id, int verify, int* blocks, fprintf(stderr, " loading %s\n", fn); if ((st.st_size % BLOCKSIZE) != 0) { - fprintf(stderr, "%s size %zd not multiple of block size %d", fn, st.st_size, BLOCKSIZE); + fprintf(stderr, "%s size %" PRId64 " not multiple of block size %d", + fn, static_cast<int64_t>(st.st_size), BLOCKSIZE); goto lsout; } @@ -671,7 +725,7 @@ static int WriteStash(const char* base, const char* id, int blocks, uint8_t* buf fprintf(stderr, " writing %d blocks to %s\n", blocks, cn); - fd = TEMP_FAILURE_RETRY(open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, STASH_FILE_MODE)); + fd = TEMP_FAILURE_RETRY(open(fn, O_WRONLY | O_CREAT | O_TRUNC, STASH_FILE_MODE)); if (fd == -1) { fprintf(stderr, "failed to create \"%s\": %s\n", fn, strerror(errno)); @@ -815,7 +869,6 @@ csout: static int SaveStash(const char* base, char** wordsave, uint8_t** buffer, size_t* buffer_alloc, int fd, int usehash, int* isunresumable) { char *id = NULL; - int res = -1; int blocks = 0; if (!wordsave || !buffer || !buffer_alloc || !isunresumable) { @@ -911,7 +964,6 @@ static int LoadSrcTgtVersion2(char** wordsave, RangeSet** tgt, int* src_blocks, char* word; char* colonsave; char* colon; - int id; int res; RangeSet* locs; size_t stashalloc = 0; @@ -1027,7 +1079,6 @@ static int LoadSrcTgtVersion3(CommandParameters* params, RangeSet** tgt, int* sr char* srchash = NULL; char* tgthash = NULL; int stash_exists = 0; - int overlap_blocks = 0; int rc = -1; uint8_t* tgtbuffer = NULL; @@ -1450,7 +1501,7 @@ static int PerformCommandErase(CommandParameters* params) { range = strtok_r(NULL, " ", ¶ms->cpos); if (range == NULL) { - fprintf(stderr, "missing target blocks for zero\n"); + fprintf(stderr, "missing target blocks for erase\n"); goto pceout; } @@ -1625,7 +1676,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int argc, // The data in transfer_list_value is not necessarily null-terminated, so we need // to copy it to a new buffer and add the null that strtok_r will need. - transfer_list = malloc(transfer_list_value->size + 1); + transfer_list = reinterpret_cast<char*>(malloc(transfer_list_value->size + 1)); if (transfer_list == NULL) { fprintf(stderr, "failed to allocate %zd bytes for transfer list\n", @@ -1726,6 +1777,10 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int argc, } if (params.canwrite) { + if (fsync(params.fd) == -1) { + fprintf(stderr, "fsync failed: %s\n", strerror(errno)); + goto pbiudone; + } fprintf(cmd_pipe, "set_progress %.4f\n", (double) params.written / total_blocks); fflush(cmd_pipe); } @@ -1903,13 +1958,15 @@ Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) { goto done; } - int fd = open(blockdev_filename->data, O_RDWR); + int fd; + fd = open(blockdev_filename->data, O_RDWR); if (fd < 0) { ErrorAbort(state, "open \"%s\" failed: %s", blockdev_filename->data, strerror(errno)); goto done; } - RangeSet* rs = parse_range(ranges->data); + RangeSet* rs; + rs = parse_range(ranges->data); uint8_t buffer[BLOCKSIZE]; SHA_CTX ctx; diff --git a/updater/install.c b/updater/install.cpp index 01a5dd24b..422a1bb1e 100644 --- a/updater/install.c +++ b/updater/install.cpp @@ -61,6 +61,11 @@ void uiPrint(State* state, char* buffer) { line = strtok(NULL, "\n"); } fprintf(ui->cmd_pipe, "ui_print\n"); + + // The recovery will only print the contents to screen for pipe command + // ui_print. We need to dump the contents to stderr (which has been + // redirected to the log file) directly. + fprintf(stderr, "%s", buffer); } __attribute__((__format__(printf, 2, 3))) __nonnull((2)) @@ -75,9 +80,9 @@ void uiPrintf(State* state, const char* format, ...) { // Take a sha-1 digest and return it as a newly-allocated hex string. char* PrintSha1(const uint8_t* digest) { - char* buffer = malloc(SHA_DIGEST_SIZE*2 + 1); - int i; + char* buffer = reinterpret_cast<char*>(malloc(SHA_DIGEST_SIZE*2 + 1)); const char* alphabet = "0123456789abcdef"; + size_t i; for (i = 0; i < SHA_DIGEST_SIZE; ++i) { buffer[i*2] = alphabet[(digest[i] >> 4) & 0xf]; buffer[i*2+1] = alphabet[digest[i] & 0xf]; @@ -133,18 +138,20 @@ Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) { goto done; } - char *secontext = NULL; + { + char *secontext = NULL; - if (sehandle) { - selabel_lookup(sehandle, &secontext, mount_point, 0755); - setfscreatecon(secontext); - } + if (sehandle) { + selabel_lookup(sehandle, &secontext, mount_point, 0755); + setfscreatecon(secontext); + } - mkdir(mount_point, 0755); + mkdir(mount_point, 0755); - if (secontext) { - freecon(secontext); - setfscreatecon(NULL); + if (secontext) { + freecon(secontext); + setfscreatecon(NULL); + } } if (strcmp(partition_type, "MTD") == 0) { @@ -202,11 +209,13 @@ Value* IsMountedFn(const char* name, State* state, int argc, Expr* argv[]) { } scan_mounted_volumes(); - const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); - if (vol == NULL) { - result = strdup(""); - } else { - result = mount_point; + { + const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); + if (vol == NULL) { + result = strdup(""); + } else { + result = mount_point; + } } done: @@ -230,17 +239,19 @@ Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) { } scan_mounted_volumes(); - const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); - if (vol == NULL) { - uiPrintf(state, "unmount of %s failed; no such volume\n", mount_point); - result = strdup(""); - } else { - int ret = unmount_mounted_volume(vol); - if (ret != 0) { - uiPrintf(state, "unmount of %s failed (%d): %s\n", - mount_point, ret, strerror(errno)); + { + const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point); + if (vol == NULL) { + uiPrintf(state, "unmount of %s failed; no such volume\n", mount_point); + result = strdup(""); + } else { + int ret = unmount_mounted_volume(vol); + if (ret != 0) { + uiPrintf(state, "unmount of %s failed (%d): %s\n", + mount_point, ret, strerror(errno)); + } + result = mount_point; } - result = mount_point; } done: @@ -413,9 +424,8 @@ done: } Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) { - char** paths = malloc(argc * sizeof(char*)); - int i; - for (i = 0; i < argc; ++i) { + char** paths = reinterpret_cast<char**>(malloc(argc * sizeof(char*))); + for (int i = 0; i < argc; ++i) { paths[i] = Evaluate(state, argv[i]); if (paths[i] == NULL) { int j; @@ -430,7 +440,7 @@ Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) { bool recursive = (strcmp(name, "delete_recursive") == 0); int success = 0; - for (i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { if ((recursive ? dirUnlinkHierarchy(paths[i]) : unlink(paths[i])) == 0) ++success; free(paths[i]); @@ -517,8 +527,6 @@ Value* PackageExtractFileFn(const char* name, State* state, } bool success = false; - UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); - if (argc == 2) { // The two-argument version extracts to a file. @@ -534,14 +542,16 @@ Value* PackageExtractFileFn(const char* name, State* state, goto done2; } - FILE* f = fopen(dest_path, "wb"); - if (f == NULL) { - printf("%s: can't open %s for write: %s\n", - name, dest_path, strerror(errno)); - goto done2; + { + FILE* f = fopen(dest_path, "wb"); + if (f == NULL) { + printf("%s: can't open %s for write: %s\n", + name, dest_path, strerror(errno)); + goto done2; + } + success = mzExtractZipEntryToFile(za, entry, fileno(f)); + fclose(f); } - success = mzExtractZipEntryToFile(za, entry, fileno(f)); - fclose(f); done2: free(zip_path); @@ -552,7 +562,7 @@ Value* PackageExtractFileFn(const char* name, State* state, // as the result. char* zip_path; - Value* v = malloc(sizeof(Value)); + Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value))); v->type = VAL_BLOB; v->size = -1; v->data = NULL; @@ -567,7 +577,7 @@ Value* PackageExtractFileFn(const char* name, State* state, } v->size = mzGetZipEntryUncompLen(entry); - v->data = malloc(v->size); + v->data = reinterpret_cast<char*>(malloc(v->size)); if (v->data == NULL) { printf("%s: failed to allocate %ld bytes for %s\n", name, (long)v->size, zip_path); @@ -866,17 +876,14 @@ static int do_SetMetadataRecursive(const char* filename, const struct stat *stat } static Value* SetMetadataFn(const char* name, State* state, int argc, Expr* argv[]) { - int i; int bad = 0; - static int nwarnings = 0; struct stat sb; Value* result = NULL; bool recursive = (strcmp(name, "set_metadata_recursive") == 0); if ((argc % 2) != 1) { - return ErrorAbort(state, "%s() expects an odd number of arguments, got %d", - name, argc); + return ErrorAbort(state, "%s() expects an odd number of arguments, got %d", name, argc); } char** args = ReadVarArgs(state, argc, argv); @@ -887,20 +894,22 @@ static Value* SetMetadataFn(const char* name, State* state, int argc, Expr* argv goto done; } - struct perm_parsed_args parsed = ParsePermArgs(state, argc, args); + { + struct perm_parsed_args parsed = ParsePermArgs(state, argc, args); - if (recursive) { - recursive_parsed_args = parsed; - recursive_state = state; - bad += nftw(args[0], do_SetMetadataRecursive, 30, FTW_CHDIR | FTW_DEPTH | FTW_PHYS); - memset(&recursive_parsed_args, 0, sizeof(recursive_parsed_args)); - recursive_state = NULL; - } else { - bad += ApplyParsedPerms(state, args[0], &sb, parsed); + if (recursive) { + recursive_parsed_args = parsed; + recursive_state = state; + bad += nftw(args[0], do_SetMetadataRecursive, 30, FTW_CHDIR | FTW_DEPTH | FTW_PHYS); + memset(&recursive_parsed_args, 0, sizeof(recursive_parsed_args)); + recursive_state = NULL; + } else { + bad += ApplyParsedPerms(state, args[0], &sb, parsed); + } } done: - for (i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { free(args[i]); } free(args); @@ -920,8 +929,7 @@ Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 1) { return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc); } - char* key; - key = Evaluate(state, argv[0]); + char* key = Evaluate(state, argv[0]); if (key == NULL) return NULL; char value[PROPERTY_VALUE_MAX]; @@ -948,29 +956,27 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { struct stat st; if (stat(filename, &st) < 0) { - ErrorAbort(state, "%s: failed to stat \"%s\": %s", - name, filename, strerror(errno)); + ErrorAbort(state, "%s: failed to stat \"%s\": %s", name, filename, strerror(errno)); goto done; } #define MAX_FILE_GETPROP_SIZE 65536 if (st.st_size > MAX_FILE_GETPROP_SIZE) { - ErrorAbort(state, "%s too large for %s (max %d)", - filename, name, MAX_FILE_GETPROP_SIZE); + ErrorAbort(state, "%s too large for %s (max %d)", filename, name, MAX_FILE_GETPROP_SIZE); goto done; } - buffer = malloc(st.st_size+1); + buffer = reinterpret_cast<char*>(malloc(st.st_size+1)); if (buffer == NULL) { ErrorAbort(state, "%s: failed to alloc %lld bytes", name, (long long)st.st_size+1); goto done; } - FILE* f = fopen(filename, "rb"); + FILE* f; + f = fopen(filename, "rb"); if (f == NULL) { - ErrorAbort(state, "%s: failed to open %s: %s", - name, filename, strerror(errno)); + ErrorAbort(state, "%s: failed to open %s: %s", name, filename, strerror(errno)); goto done; } @@ -984,7 +990,8 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { fclose(f); - char* line = strtok(buffer, "\n"); + char* line; + line = strtok(buffer, "\n"); do { // skip whitespace at start of line while (*line && isspace(*line)) ++line; @@ -1028,15 +1035,6 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { return StringValue(result); } - -static bool write_raw_image_cb(const unsigned char* data, - int data_len, void* ctx) { - int r = mtd_write_data((MtdWriteContext*)ctx, (const char *)data, data_len); - if (r == data_len) return true; - printf("%s\n", strerror(errno)); - return false; -} - // write_raw_image(filename_or_blob, partition) Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) { char* result = NULL; @@ -1063,14 +1061,16 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) { } mtd_scan_partitions(); - const MtdPartition* mtd = mtd_find_partition_by_name(partition); + const MtdPartition* mtd; + mtd = mtd_find_partition_by_name(partition); if (mtd == NULL) { printf("%s: no mtd partition named \"%s\"\n", name, partition); result = strdup(""); goto done; } - MtdWriteContext* ctx = mtd_write_partition(mtd); + MtdWriteContext* ctx; + ctx = mtd_write_partition(mtd); if (ctx == NULL) { printf("%s: can't write mtd partition \"%s\"\n", name, partition); @@ -1085,14 +1085,13 @@ Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) { char* filename = contents->data; FILE* f = fopen(filename, "rb"); if (f == NULL) { - printf("%s: can't open %s: %s\n", - name, filename, strerror(errno)); + printf("%s: can't open %s: %s\n", name, filename, strerror(errno)); result = strdup(""); goto done; } success = true; - char* buffer = malloc(BUFSIZ); + char* buffer = reinterpret_cast<char*>(malloc(BUFSIZ)); int read; while (success && (read = fread(buffer, 1, BUFSIZ, f)) > 0) { int wrote = mtd_write_data(ctx, buffer, read); @@ -1139,8 +1138,7 @@ Value* ApplyPatchSpaceFn(const char* name, State* state, char* endptr; size_t bytes = strtol(bytes_str, &endptr, 10); if (bytes == 0 && endptr == bytes_str) { - ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n", - name, bytes_str); + ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n", name, bytes_str); free(bytes_str); return NULL; } @@ -1200,7 +1198,7 @@ Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) { return NULL; } - char** patch_sha_str = malloc(patchcount * sizeof(char*)); + char** patch_sha_str = reinterpret_cast<char**>(malloc(patchcount * sizeof(char*))); for (i = 0; i < patchcount; ++i) { patch_sha_str[i] = patches[i*2]->data; patches[i*2]->data = NULL; @@ -1259,7 +1257,7 @@ Value* UIPrintFn(const char* name, State* state, int argc, Expr* argv[]) { for (i = 0; i < argc; ++i) { size += strlen(args[i]); } - char* buffer = malloc(size+1); + char* buffer = reinterpret_cast<char*>(malloc(size+1)); size = 0; for (i = 0; i < argc; ++i) { strcpy(buffer+size, args[i]); @@ -1289,7 +1287,7 @@ Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) { return NULL; } - char** args2 = malloc(sizeof(char*) * (argc+1)); + char** args2 = reinterpret_cast<char**>(malloc(sizeof(char*) * (argc+1))); memcpy(args2, args, sizeof(char*) * argc); args2[argc] = NULL; @@ -1356,7 +1354,7 @@ Value* Sha1CheckFn(const char* name, State* state, int argc, Expr* argv[]) { } int i; - uint8_t* arg_digest = malloc(SHA_DIGEST_SIZE); + uint8_t* arg_digest = reinterpret_cast<uint8_t*>(malloc(SHA_DIGEST_SIZE)); for (i = 1; i < argc; ++i) { if (args[i]->type != VAL_STRING) { printf("%s(): arg %d is not a string; skipping", @@ -1392,7 +1390,7 @@ Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) { char* filename; if (ReadArgs(state, argv, 1, &filename) < 0) return NULL; - Value* v = malloc(sizeof(Value)); + Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value))); v->type = VAL_BLOB; FileContents fc; @@ -1550,15 +1548,14 @@ Value* Tune2FsFn(const char* name, State* state, int argc, Expr* argv[]) { return ErrorAbort(state, "%s() could not read args", name); } - int i; - char** args2 = malloc(sizeof(char*) * (argc+1)); + char** args2 = reinterpret_cast<char**>(malloc(sizeof(char*) * (argc+1))); // Tune2fs expects the program name as its args[0] args2[0] = strdup(name); - for (i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { args2[i + 1] = args[i]; } int result = tune2fs_main(argc + 1, args2); - for (i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { free(args[i]); } free(args); diff --git a/updater/updater.c b/updater/updater.cpp index 661f69587..0f22e6d04 100644 --- a/updater/updater.c +++ b/updater/updater.cpp @@ -89,7 +89,7 @@ int main(int argc, char** argv) { return 4; } - char* script = malloc(script_entry->uncompLen+1); + char* script = reinterpret_cast<char*>(malloc(script_entry->uncompLen+1)); if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) { printf("failed to read script from package\n"); return 5; |