|
|
b837a6 |
From a3655b7bf64b7e016602d0b2bec450d27575816e Mon Sep 17 00:00:00 2001
|
|
|
b837a6 |
From: Peter Jones <pjones@redhat.com>
|
|
|
b837a6 |
Date: Mon, 15 Oct 2012 13:12:53 -0400
|
|
|
b837a6 |
Subject: [PATCH 3/4] Fixes for problems discovered by coverity scan.
|
|
|
b837a6 |
|
|
|
b837a6 |
Related: rhbz#1085434
|
|
|
b837a6 |
|
|
|
b837a6 |
Signed-off-by: Peter Jones <pjones@fedoraproject.org>
|
|
|
b837a6 |
---
|
|
|
b837a6 |
extlinux/main.c | 9 ++++++++-
|
|
|
b837a6 |
libfat/fat.h | 9 +++++++--
|
|
|
b837a6 |
libinstaller/advio.c | 17 +++++++++--------
|
|
|
b837a6 |
libinstaller/syslxcom.c | 8 ++++++++
|
|
|
b837a6 |
libinstaller/syslxint.h | 10 +++++++---
|
|
|
b837a6 |
linux/syslinux.c | 3 ---
|
|
|
b837a6 |
mtools/syslinux.c | 1 +
|
|
|
b837a6 |
utils/Makefile | 2 +-
|
|
|
b837a6 |
utils/isohybrid.c | 20 ++++++++++++++------
|
|
|
b837a6 |
9 files changed, 55 insertions(+), 24 deletions(-)
|
|
|
b837a6 |
|
|
|
b837a6 |
diff --git a/extlinux/main.c b/extlinux/main.c
|
|
|
b837a6 |
index e574051..a461533 100755
|
|
|
b837a6 |
--- a/extlinux/main.c
|
|
|
b837a6 |
+++ b/extlinux/main.c
|
|
|
b837a6 |
@@ -292,7 +292,12 @@ int patch_file_and_bootblock(int fd, const char *dir, int devfd)
|
|
|
b837a6 |
nsect = (boot_image_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
|
|
|
b837a6 |
nsect += 2; /* Two sectors for the ADV */
|
|
|
b837a6 |
sectp = alloca(sizeof(sector_t) * nsect);
|
|
|
b837a6 |
- if (fs_type == EXT2 || fs_type == VFAT) {
|
|
|
b837a6 |
+ if (sectp == NULL) {
|
|
|
b837a6 |
+ perror("alloca");
|
|
|
b837a6 |
+ exit(1);
|
|
|
b837a6 |
+ }
|
|
|
b837a6 |
+ memset(sectp, '\0', sizeof(sector_t) * nsect);
|
|
|
b837a6 |
+ if (fd >= 0 && (fs_type == EXT2 || fs_type == VFAT)) {
|
|
|
b837a6 |
if (sectmap(fd, sectp, nsect)) {
|
|
|
b837a6 |
perror("bmap");
|
|
|
b837a6 |
exit(1);
|
|
|
b837a6 |
@@ -423,6 +428,8 @@ int ext2_fat_install_file(const char *path, int devfd, struct stat *rst)
|
|
|
b837a6 |
|
|
|
b837a6 |
/* Map the file, and patch the initial sector accordingly */
|
|
|
b837a6 |
modbytes = patch_file_and_bootblock(fd, path, devfd);
|
|
|
b837a6 |
+ if (modbytes < 0)
|
|
|
b837a6 |
+ goto bail;
|
|
|
b837a6 |
|
|
|
b837a6 |
/* Write the patch area again - this relies on the file being
|
|
|
b837a6 |
overwritten in place! */
|
|
|
b837a6 |
diff --git a/libfat/fat.h b/libfat/fat.h
|
|
|
b837a6 |
index b4e32f7..acafdb6 100644
|
|
|
b837a6 |
--- a/libfat/fat.h
|
|
|
b837a6 |
+++ b/libfat/fat.h
|
|
|
b837a6 |
@@ -23,8 +23,13 @@
|
|
|
b837a6 |
|
|
|
b837a6 |
/* The poor excuse FAT has for a superblock -- in the boot sector */
|
|
|
b837a6 |
struct fat_bootsect {
|
|
|
b837a6 |
- le8_t bsJump[3]; /* Jump to code */
|
|
|
b837a6 |
- char bsOemName[8]; /* Formatting program */
|
|
|
b837a6 |
+ union {
|
|
|
b837a6 |
+ struct {
|
|
|
b837a6 |
+ uint8_t bsJump[3]; /* Jump to code */
|
|
|
b837a6 |
+ char bsOemName[8]; /* Formatting program */
|
|
|
b837a6 |
+ };
|
|
|
b837a6 |
+ uint8_t bsHead[11];
|
|
|
b837a6 |
+ };
|
|
|
b837a6 |
le16_t bsBytesPerSec; /* Bytes/sector */
|
|
|
b837a6 |
le8_t bsSecPerClust; /* Sectors/cluster */
|
|
|
b837a6 |
le16_t bsResSectors; /* Reserved sectors */
|
|
|
b837a6 |
diff --git a/libinstaller/advio.c b/libinstaller/advio.c
|
|
|
b837a6 |
index 56f607d..01894f2 100644
|
|
|
b837a6 |
--- a/libinstaller/advio.c
|
|
|
b837a6 |
+++ b/libinstaller/advio.c
|
|
|
b837a6 |
@@ -135,15 +135,16 @@ int write_adv(const char *path, const char *cfg)
|
|
|
b837a6 |
xst.st_dev != st.st_dev || xst.st_size != st.st_size) {
|
|
|
b837a6 |
fprintf(stderr, "%s: race condition on write\n", file);
|
|
|
b837a6 |
err = -2;
|
|
|
b837a6 |
+ } else {
|
|
|
b837a6 |
+ /* Write our own version ... */
|
|
|
b837a6 |
+ if (xpwrite(fd, syslinux_adv, 2 * ADV_SIZE,
|
|
|
b837a6 |
+ st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) {
|
|
|
b837a6 |
+ err = -1;
|
|
|
b837a6 |
+ }
|
|
|
b837a6 |
+
|
|
|
b837a6 |
+ sync();
|
|
|
b837a6 |
+ set_attributes(fd);
|
|
|
b837a6 |
}
|
|
|
b837a6 |
- /* Write our own version ... */
|
|
|
b837a6 |
- if (xpwrite(fd, syslinux_adv, 2 * ADV_SIZE,
|
|
|
b837a6 |
- st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) {
|
|
|
b837a6 |
- err = -1;
|
|
|
b837a6 |
- }
|
|
|
b837a6 |
-
|
|
|
b837a6 |
- sync();
|
|
|
b837a6 |
- set_attributes(fd);
|
|
|
b837a6 |
}
|
|
|
b837a6 |
}
|
|
|
b837a6 |
|
|
|
b837a6 |
diff --git a/libinstaller/syslxcom.c b/libinstaller/syslxcom.c
|
|
|
b837a6 |
index a6a8339..dae81bc 100644
|
|
|
b837a6 |
--- a/libinstaller/syslxcom.c
|
|
|
b837a6 |
+++ b/libinstaller/syslxcom.c
|
|
|
b837a6 |
@@ -87,6 +87,9 @@ ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
|
|
|
b837a6 |
ssize_t rv;
|
|
|
b837a6 |
ssize_t done = 0;
|
|
|
b837a6 |
|
|
|
b837a6 |
+ if (fd < 0)
|
|
|
b837a6 |
+ die(strerror(EBADF));
|
|
|
b837a6 |
+
|
|
|
b837a6 |
while (count) {
|
|
|
b837a6 |
rv = pwrite(fd, bufp, count, offset);
|
|
|
b837a6 |
if (rv == 0) {
|
|
|
b837a6 |
@@ -279,6 +282,11 @@ static int sectmap_fib(int fd, sector_t *sectors, int nsectors)
|
|
|
b837a6 |
*/
|
|
|
b837a6 |
int sectmap(int fd, sector_t *sectors, int nsectors)
|
|
|
b837a6 |
{
|
|
|
b837a6 |
+ if (fd < 0) {
|
|
|
b837a6 |
+ errno = EBADF;
|
|
|
b837a6 |
+ return -1;
|
|
|
b837a6 |
+ }
|
|
|
b837a6 |
+
|
|
|
b837a6 |
if (!sectmap_fie(fd, sectors, nsectors))
|
|
|
b837a6 |
return 0;
|
|
|
b837a6 |
|
|
|
b837a6 |
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
|
|
|
b837a6 |
index 7c9da51..8d39f74 100644
|
|
|
b837a6 |
--- a/libinstaller/syslxint.h
|
|
|
b837a6 |
+++ b/libinstaller/syslxint.h
|
|
|
b837a6 |
@@ -193,8 +193,13 @@ struct syslinux_extent {
|
|
|
b837a6 |
|
|
|
b837a6 |
/* FAT bootsector format, also used by other disk-based derivatives */
|
|
|
b837a6 |
struct boot_sector {
|
|
|
b837a6 |
- uint8_t bsJump[3];
|
|
|
b837a6 |
- char bsOemName[8];
|
|
|
b837a6 |
+ union {
|
|
|
b837a6 |
+ struct {
|
|
|
b837a6 |
+ uint8_t bsJump[3];
|
|
|
b837a6 |
+ char bsOemName[8];
|
|
|
b837a6 |
+ };
|
|
|
b837a6 |
+ uint8_t bsHead[11];
|
|
|
b837a6 |
+ };
|
|
|
b837a6 |
uint16_t bsBytesPerSec;
|
|
|
b837a6 |
uint8_t bsSecPerClust;
|
|
|
b837a6 |
uint16_t bsResSectors;
|
|
|
b837a6 |
@@ -241,7 +246,6 @@ struct boot_sector {
|
|
|
b837a6 |
uint16_t bsSignature;
|
|
|
b837a6 |
} __attribute__ ((packed));
|
|
|
b837a6 |
|
|
|
b837a6 |
-#define bsHead bsJump
|
|
|
b837a6 |
#define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec)
|
|
|
b837a6 |
#define bsCode bs32.Code /* The common safe choice */
|
|
|
b837a6 |
#define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
|
|
|
b837a6 |
diff --git a/linux/syslinux.c b/linux/syslinux.c
|
|
|
b837a6 |
index c7a9ecc..6e23a7a 100755
|
|
|
b837a6 |
--- a/linux/syslinux.c
|
|
|
b837a6 |
+++ b/linux/syslinux.c
|
|
|
b837a6 |
@@ -335,9 +335,6 @@ int main(int argc, char *argv[])
|
|
|
b837a6 |
snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d",
|
|
|
b837a6 |
(unsigned long)mypid, i);
|
|
|
b837a6 |
|
|
|
b837a6 |
- if (lstat(mntname, &dst) != -1 || errno != ENOENT)
|
|
|
b837a6 |
- continue;
|
|
|
b837a6 |
-
|
|
|
b837a6 |
rv = mkdir(mntname, 0000);
|
|
|
b837a6 |
|
|
|
b837a6 |
if (rv == -1) {
|
|
|
b837a6 |
diff --git a/mtools/syslinux.c b/mtools/syslinux.c
|
|
|
b837a6 |
index ac189c6..4bec0e3 100755
|
|
|
b837a6 |
--- a/mtools/syslinux.c
|
|
|
b837a6 |
+++ b/mtools/syslinux.c
|
|
|
b837a6 |
@@ -208,6 +208,7 @@ int main(int argc, char *argv[])
|
|
|
b837a6 |
!mtools_conf)
|
|
|
b837a6 |
die_err(tmpdir);
|
|
|
b837a6 |
|
|
|
b837a6 |
+ umask(077);
|
|
|
b837a6 |
mtc_fd = mkstemp(mtools_conf);
|
|
|
b837a6 |
if (mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w")))
|
|
|
b837a6 |
die_err(mtools_conf);
|
|
|
b837a6 |
diff --git a/utils/Makefile b/utils/Makefile
|
|
|
b837a6 |
index 44cb54f..4fabe04 100644
|
|
|
b837a6 |
--- a/utils/Makefile
|
|
|
b837a6 |
+++ b/utils/Makefile
|
|
|
b837a6 |
@@ -51,7 +51,7 @@ isohdpfx.c: $(ISOHDPFX) isohdpfxarray.pl
|
|
|
b837a6 |
$(PERL) isohdpfxarray.pl $(ISOHDPFX) > $@
|
|
|
b837a6 |
|
|
|
b837a6 |
isohybrid: isohybrid.o isohdpfx.o
|
|
|
b837a6 |
- $(CC) $(LDFLAGS) -luuid -o $@ $^
|
|
|
b837a6 |
+ $(CC) $(LDFLAGS) -fshort-wchar -luuid -o $@ $^
|
|
|
b837a6 |
|
|
|
b837a6 |
gethostip: gethostip.o
|
|
|
b837a6 |
$(CC) $(LDFLAGS) -o $@ $^
|
|
|
b837a6 |
diff --git a/utils/isohybrid.c b/utils/isohybrid.c
|
|
|
b837a6 |
index ac04bfd..865c114 100644
|
|
|
b837a6 |
--- a/utils/isohybrid.c
|
|
|
b837a6 |
+++ b/utils/isohybrid.c
|
|
|
b837a6 |
@@ -357,6 +357,8 @@ check_option(int argc, char *argv[])
|
|
|
b837a6 |
case ':':
|
|
|
b837a6 |
errx(1, "option `-%c' takes an argument", optopt);
|
|
|
b837a6 |
|
|
|
b837a6 |
+ printh();
|
|
|
b837a6 |
+ exit(0);
|
|
|
b837a6 |
default:
|
|
|
b837a6 |
case '?':
|
|
|
b837a6 |
if (optopt)
|
|
|
b837a6 |
@@ -618,7 +620,7 @@ initialise_mbr(uint8_t *mbr)
|
|
|
b837a6 |
bsect = (offset % sector) + 1;
|
|
|
b837a6 |
bcyle = offset / (head * sector);
|
|
|
b837a6 |
|
|
|
b837a6 |
- bsect += (bcyle & 0x300) >> 2;
|
|
|
b837a6 |
+ bsect += bcyle >> 2;
|
|
|
b837a6 |
bcyle &= 0xFF;
|
|
|
b837a6 |
|
|
|
b837a6 |
ehead = head - 1;
|
|
|
b837a6 |
@@ -792,7 +794,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
|
|
|
b837a6 |
memcpy(part->partTypeGUID, basic_partition, sizeof(uuid_t));
|
|
|
b837a6 |
part->firstLBA = lendian_64(0);
|
|
|
b837a6 |
part->lastLBA = lendian_64(psize);
|
|
|
b837a6 |
- memcpy(part->name, "ISOHybrid ISO", 28);
|
|
|
b837a6 |
+ memcpy(part->name, L"ISOHybrid ISO", 28);
|
|
|
b837a6 |
|
|
|
b837a6 |
gpt += sizeof(struct gpt_part_header);
|
|
|
b837a6 |
part++;
|
|
|
b837a6 |
@@ -801,7 +803,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
|
|
|
b837a6 |
memcpy(part->partTypeGUID, basic_partition, sizeof(uuid_t));
|
|
|
b837a6 |
part->firstLBA = lendian_64(efi_lba * 4);
|
|
|
b837a6 |
part->lastLBA = lendian_64(part->firstLBA + efi_count - 1);
|
|
|
b837a6 |
- memcpy(part->name, "ISOHybrid", 20);
|
|
|
b837a6 |
+ memcpy(part->name, L"ISOHybrid", 20);
|
|
|
b837a6 |
|
|
|
b837a6 |
gpt += sizeof(struct gpt_part_header);
|
|
|
b837a6 |
|
|
|
b837a6 |
@@ -814,7 +816,7 @@ initialise_gpt(uint8_t *gpt, uint32_t current, uint32_t alternate, int primary)
|
|
|
b837a6 |
memcpy(part->partTypeGUID, hfs_partition, sizeof(uuid_t));
|
|
|
b837a6 |
part->firstLBA = lendian_64(mac_lba * 4);
|
|
|
b837a6 |
part->lastLBA = lendian_64(part->firstLBA + mac_count - 1);
|
|
|
b837a6 |
- memcpy(part->name, "ISOHybrid", 20);
|
|
|
b837a6 |
+ memcpy(part->name, L"ISOHybrid", 20);
|
|
|
b837a6 |
|
|
|
b837a6 |
part--;
|
|
|
b837a6 |
}
|
|
|
b837a6 |
@@ -891,7 +893,11 @@ main(int argc, char *argv[])
|
|
|
b837a6 |
size_t orig_gpt_size, free_space, gpt_size;
|
|
|
b837a6 |
struct iso_primary_descriptor descriptor;
|
|
|
b837a6 |
|
|
|
b837a6 |
- prog = strcpy(alloca(strlen(argv[0]) + 1), argv[0]);
|
|
|
b837a6 |
+ prog = alloca(strlen(argv[0]) + 1);
|
|
|
b837a6 |
+ if (!prog)
|
|
|
b837a6 |
+ err(1, "");
|
|
|
b837a6 |
+ strcpy(prog, argv[0]);
|
|
|
b837a6 |
+
|
|
|
b837a6 |
i = check_option(argc, argv);
|
|
|
b837a6 |
argc -= i;
|
|
|
b837a6 |
argv += i;
|
|
|
b837a6 |
@@ -1097,7 +1103,9 @@ main(int argc, char *argv[])
|
|
|
b837a6 |
|
|
|
b837a6 |
initialise_apm(buf, APM_OFFSET);
|
|
|
b837a6 |
|
|
|
b837a6 |
- fseek(fp, APM_OFFSET, SEEK_SET);
|
|
|
b837a6 |
+ if (fseek(fp, APM_OFFSET, SEEK_SET))
|
|
|
b837a6 |
+ err(1, "%s: seek error - 7", argv[0]);
|
|
|
b837a6 |
+
|
|
|
b837a6 |
fwrite(buf, sizeof(char), apm_size, fp);
|
|
|
b837a6 |
}
|
|
|
b837a6 |
|
|
|
b837a6 |
--
|
|
|
b837a6 |
1.9.3
|
|
|
b837a6 |
|