Merge "Cleanup uses of sprintf, add modes to open() with O_CREAT."

This commit is contained in:
George Burgess 2016-03-03 00:07:39 +00:00 committed by Android (Google) Code Review
commit 972c545f7e
6 changed files with 17 additions and 12 deletions

View file

@ -4035,7 +4035,7 @@ static status_t CreateFile(const char* name, int len) {
LOG(ERROR) << "Failed to read random data";
return -EIO;
}
if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC))) < 0) {
if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644))) < 0) {
PLOG(ERROR) << "Failed to open " << name;
return -errno;
}

View file

@ -47,7 +47,7 @@ int Loop::dumpState(SocketClient *c) {
struct loop_info64 li;
int rc;
sprintf(filename, "/dev/block/loop%d", i);
snprintf(filename, sizeof(filename), "/dev/block/loop%d", i);
if ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
if (errno != ENOENT) {
@ -91,7 +91,7 @@ int Loop::lookupActive(const char *id, char *buffer, size_t len) {
struct loop_info64 li;
int rc;
sprintf(filename, "/dev/block/loop%d", i);
snprintf(filename, sizeof(filename), "/dev/block/loop%d", i);
if ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
if (errno != ENOENT) {
@ -137,7 +137,7 @@ int Loop::create(const char *id, const char *loopFile, char *loopDeviceBuffer, s
int rc;
char *secontext = NULL;
sprintf(filename, "/dev/block/loop%d", i);
snprintf(filename, sizeof(filename), "/dev/block/loop%d", i);
/*
* The kernel starts us off with 8 loop nodes, but more

View file

@ -85,7 +85,7 @@ int Process::checkFileDescriptorSymLinks(int pid, const char *mountPoint, char *
// compute path to process's directory of open files
char path[PATH_MAX];
sprintf(path, "/proc/%d/fd", pid);
snprintf(path, sizeof(path), "/proc/%d/fd", pid);
DIR *dir = opendir(path);
if (!dir)
return 0;
@ -129,7 +129,7 @@ int Process::checkFileMaps(int pid, const char *mountPoint, char *openFilename,
FILE *file;
char buffer[PATH_MAX + 100];
sprintf(buffer, "/proc/%d/maps", pid);
snprintf(buffer, sizeof(buffer), "/proc/%d/maps", pid);
file = fopen(buffer, "r");
if (!file)
return 0;
@ -155,7 +155,7 @@ int Process::checkSymLink(int pid, const char *mountPoint, const char *name) {
char path[PATH_MAX];
char link[PATH_MAX];
sprintf(path, "/proc/%d/%s", pid, name);
snprintf(path, sizeof(path), "/proc/%d/%s", pid, name);
if (readSymLink(path, link, sizeof(link)) && pathMatchesMountPoint(link, mountPoint))
return 1;
return 0;

View file

@ -278,7 +278,7 @@ static status_t CreateFile(const char* name, int len) {
LOG(ERROR) << "Failed to read random data";
return -EIO;
}
if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC))) < 0) {
if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644))) < 0) {
PLOG(ERROR) << "Failed to open " << name;
return -errno;
}

View file

@ -1064,6 +1064,7 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr,
struct dm_target_spec *tgt;
char *crypt_params;
char master_key_ascii[129]; /* Large enough to hold 512 bit key and null */
size_t buff_offset;
int i;
io = (struct dm_ioctl *) buffer;
@ -1089,8 +1090,11 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr,
crypt_params = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec);
convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii);
sprintf(crypt_params, "%s %s 0 %s 0 %s", crypt_ftr->crypto_type_name,
master_key_ascii, real_blk_name, extra_params);
buff_offset = crypt_params - buffer;
snprintf(crypt_params, sizeof(buffer) - buff_offset, "%s %s 0 %s 0 %s",
crypt_ftr->crypto_type_name, master_key_ascii, real_blk_name,
extra_params);
crypt_params += strlen(crypt_params) + 1;
crypt_params = (char *) (((unsigned long)crypt_params + 7) & ~8); /* Align to an 8 byte boundary */
tgt->next = crypt_params - buffer;
@ -1883,7 +1887,8 @@ static int test_mount_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr,
} else {
/* Try mounting the file system anyway, just in case the problem's with
* the footer, not the key. */
sprintf(tmp_mount_point, "%s/tmp_mnt", mount_point);
snprintf(tmp_mount_point, sizeof(tmp_mount_point), "%s/tmp_mnt",
mount_point);
mkdir(tmp_mount_point, 0755);
if (fs_mgr_do_mount(fstab, DATA_MNT_POINT, crypto_blkdev, tmp_mount_point)) {
SLOGE("Error temp mounting decrypted block device\n");

View file

@ -139,7 +139,7 @@ status_t Mount(const std::string& source, const std::string& target, bool ro,
flags |= (ro ? MS_RDONLY : 0);
flags |= (remount ? MS_REMOUNT : 0);
sprintf(mountData,
snprintf(mountData, sizeof(mountData),
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
ownerUid, ownerGid, permMask, permMask);