Maciej Sumi?ski has uploaded this change for review. ( https://review.coreboot.org/21025
Change subject: util/inteltool: Print error messages directly to stderr ......................................................................
util/inteltool: Print error messages directly to stderr
String buffers were too small to fit certain error messages, causing segfaults on errors. Using perror() with a string that already contained an error message, printed the message twice.
Change-Id: I5ccc37e404f278cafae0a451c5acaa27d7907cce Signed-off-by: Maciej Suminski maciej.suminski@cern.ch --- M util/inteltool/cpu.c 1 file changed, 4 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/25/21025/1
diff --git a/util/inteltool/cpu.c b/util/inteltool/cpu.c index 7b2e503..319eee5 100644 --- a/util/inteltool/cpu.c +++ b/util/inteltool/cpu.c @@ -111,21 +111,17 @@ static int open_and_seek(int cpu, unsigned long msr, int mode, int *fd) { char dev[512]; - char temp_string[50];
snprintf(dev, sizeof(dev), "/dev/cpu/%d/msr", cpu); *fd = open(dev, mode);
if (*fd < 0) { - sprintf(temp_string, - "open("%s"): %s\n", dev, strerror(errno)); - perror(temp_string); + fprintf(stderr, "open("%s"): %s\n", dev, strerror(errno)); return -1; }
if (lseek(*fd, msr, SEEK_SET) == (off_t)-1) { - sprintf(temp_string, "lseek(%lu): %s\n", msr, strerror(errno)); - perror(temp_string); + fprintf(stderr, "lseek(%lu): %s\n", msr, strerror(errno)); close(*fd); return -1; } @@ -138,11 +134,9 @@ int fd; msr_t msr = { 0xffffffff, 0xffffffff }; uint32_t buf[2]; - char temp_string[50];
if (open_and_seek(cpu, addr, O_RDONLY, &fd) < 0) { - sprintf(temp_string, "Could not read MSR for CPU#%d", cpu); - perror(temp_string); + fprintf(stderr, "Could not read MSR for CPU#%d\n", cpu); }
if (read(fd, buf, 8) == 8) { @@ -194,13 +188,11 @@ #ifndef __DARWIN__ int ncpus = get_number_of_cpus(); int i = 0; - char temp_string[50];
printf("\n============= Dumping INTEL SGX status =============");
if (ncpus < 1) { - sprintf(temp_string, "Failed to get number of CPUs\n"); - perror(temp_string); + fprintf(stderr, "Failed to get number of CPUs\n"); error = -1; } else { printf("\nNumber of CPUs = %d\n", ncpus);