Cleanup uses of sprintf, add modes to open() with O_CREAT.
Change-Id: Iaed2538831b19ada26005bbef33cff28209c6512
This commit is contained in:
parent
ed4800064c
commit
605d7ae18d
6 changed files with 17 additions and 12 deletions
|
@ -4035,7 +4035,7 @@ static status_t CreateFile(const char* name, int len) {
|
||||||
LOG(ERROR) << "Failed to read random data";
|
LOG(ERROR) << "Failed to read random data";
|
||||||
return -EIO;
|
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;
|
PLOG(ERROR) << "Failed to open " << name;
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
6
Loop.cpp
6
Loop.cpp
|
@ -47,7 +47,7 @@ int Loop::dumpState(SocketClient *c) {
|
||||||
struct loop_info64 li;
|
struct loop_info64 li;
|
||||||
int rc;
|
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 ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
|
@ -91,7 +91,7 @@ int Loop::lookupActive(const char *id, char *buffer, size_t len) {
|
||||||
struct loop_info64 li;
|
struct loop_info64 li;
|
||||||
int rc;
|
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 ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
|
@ -137,7 +137,7 @@ int Loop::create(const char *id, const char *loopFile, char *loopDeviceBuffer, s
|
||||||
int rc;
|
int rc;
|
||||||
char *secontext = NULL;
|
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
|
* The kernel starts us off with 8 loop nodes, but more
|
||||||
|
|
|
@ -85,7 +85,7 @@ int Process::checkFileDescriptorSymLinks(int pid, const char *mountPoint, char *
|
||||||
|
|
||||||
// compute path to process's directory of open files
|
// compute path to process's directory of open files
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
sprintf(path, "/proc/%d/fd", pid);
|
snprintf(path, sizeof(path), "/proc/%d/fd", pid);
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -129,7 +129,7 @@ int Process::checkFileMaps(int pid, const char *mountPoint, char *openFilename,
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char buffer[PATH_MAX + 100];
|
char buffer[PATH_MAX + 100];
|
||||||
|
|
||||||
sprintf(buffer, "/proc/%d/maps", pid);
|
snprintf(buffer, sizeof(buffer), "/proc/%d/maps", pid);
|
||||||
file = fopen(buffer, "r");
|
file = fopen(buffer, "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -155,7 +155,7 @@ int Process::checkSymLink(int pid, const char *mountPoint, const char *name) {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char link[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))
|
if (readSymLink(path, link, sizeof(link)) && pathMatchesMountPoint(link, mountPoint))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -278,7 +278,7 @@ static status_t CreateFile(const char* name, int len) {
|
||||||
LOG(ERROR) << "Failed to read random data";
|
LOG(ERROR) << "Failed to read random data";
|
||||||
return -EIO;
|
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;
|
PLOG(ERROR) << "Failed to open " << name;
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
11
cryptfs.c
11
cryptfs.c
|
@ -1064,6 +1064,7 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr,
|
||||||
struct dm_target_spec *tgt;
|
struct dm_target_spec *tgt;
|
||||||
char *crypt_params;
|
char *crypt_params;
|
||||||
char master_key_ascii[129]; /* Large enough to hold 512 bit key and null */
|
char master_key_ascii[129]; /* Large enough to hold 512 bit key and null */
|
||||||
|
size_t buff_offset;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
io = (struct dm_ioctl *) buffer;
|
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);
|
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);
|
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 += strlen(crypt_params) + 1;
|
||||||
crypt_params = (char *) (((unsigned long)crypt_params + 7) & ~8); /* Align to an 8 byte boundary */
|
crypt_params = (char *) (((unsigned long)crypt_params + 7) & ~8); /* Align to an 8 byte boundary */
|
||||||
tgt->next = crypt_params - buffer;
|
tgt->next = crypt_params - buffer;
|
||||||
|
@ -1883,7 +1887,8 @@ static int test_mount_encrypted_fs(struct crypt_mnt_ftr* crypt_ftr,
|
||||||
} else {
|
} else {
|
||||||
/* Try mounting the file system anyway, just in case the problem's with
|
/* Try mounting the file system anyway, just in case the problem's with
|
||||||
* the footer, not the key. */
|
* 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);
|
mkdir(tmp_mount_point, 0755);
|
||||||
if (fs_mgr_do_mount(fstab, DATA_MNT_POINT, crypto_blkdev, tmp_mount_point)) {
|
if (fs_mgr_do_mount(fstab, DATA_MNT_POINT, crypto_blkdev, tmp_mount_point)) {
|
||||||
SLOGE("Error temp mounting decrypted block device\n");
|
SLOGE("Error temp mounting decrypted block device\n");
|
||||||
|
|
|
@ -139,7 +139,7 @@ status_t Mount(const std::string& source, const std::string& target, bool ro,
|
||||||
flags |= (ro ? MS_RDONLY : 0);
|
flags |= (ro ? MS_RDONLY : 0);
|
||||||
flags |= (remount ? MS_REMOUNT : 0);
|
flags |= (remount ? MS_REMOUNT : 0);
|
||||||
|
|
||||||
sprintf(mountData,
|
snprintf(mountData, sizeof(mountData),
|
||||||
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
|
"utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
|
||||||
ownerUid, ownerGid, permMask, permMask);
|
ownerUid, ownerGid, permMask, permMask);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue