[coreboot-gerrit] Change in coreboot[master]: util/inteltool: Print error messages directly to stderr

Maciej Sumi?ski (Code Review) gerrit at coreboot.org
Wed Aug 16 00:02:47 CEST 2017


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 at 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);

-- 
To view, visit https://review.coreboot.org/21025
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ccc37e404f278cafae0a451c5acaa27d7907cce
Gerrit-Change-Number: 21025
Gerrit-PatchSet: 1
Gerrit-Owner: Maciej Sumi?ski <maciej.suminski at cern.ch>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170815/334939ba/attachment.html>


More information about the coreboot-gerrit mailing list