Skip to contentSkip to conversation

Fix string null termination and SIGABRT from glibc

PATCH In review Mikko Rapeli 3 participants 3 messages Sep 26, 2012

lore
Share & tools
lore

Mikko Rapeli

author
#0 lore raw

PATCH v2 1/1 Fix string null termination and SIGABRT from glibc

According to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=682388
the string is not null terminated when too much data is read.

This patch fixes the crashes on my system.

---
 src/process/process.cpp |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/process/process.cpp +2 -1
index 71f81b6..34dc68d 100644
@@ -86,7 +86,7 @@ static void cmdline_to_string(char *str)
 
 process::process(const char *_comm, int _pid, int _tid) : power_consumer()
 {
-	char line[4096];
+	char line[4097];
 	ifstream file;
 
 	strcpy(comm, _comm);
@@ -103,6 +103,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer()
 		file.open(line);
 		while (file) {
 			file.getline(line, 4096);
+			line[4096] = '\0';
 			if (strstr(line, "Tgid")) {
 				char *c;
 				c = strchr(line, ':');
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 8 lines · Mikko Rapeli

According to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=682388
the string is not null terminated when too much data is read.

This patch fixes the crashes on my system.

---
 src/process/process.cpp |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

LGTM, thanks!

	-ss
Quoted 29 lines
src/process/process.cpp +2 -1
index 71f81b6..34dc68d 100644
@@ -86,7 +86,7 @@ static void cmdline_to_string(char *str)
 
 process::process(const char *_comm, int _pid, int _tid) : power_consumer()
 {
-	char line[4096];
+	char line[4097];
 	ifstream file;
 
 	strcpy(comm, _comm);
@@ -103,6 +103,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer()
 		file.open(line);
 		while (file) {
 			file.getline(line, 4096);
+			line[4096] = '\0';
 			if (strstr(line, "Tgid")) {
 				char *c;
 				c = strchr(line, ':');
Signature · 6 lines
1.7.10.4

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop
#2 lore raw
Quoted 4 lines · Sergey Senozhatsky
Quoted 3 lines · Mikko Rapeli

According to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=682388
the string is not null terminated when too much data is read.

Quoted 9 lines
Quoted 5 lines

This patch fixes the crashes on my system.

---
  src/process/process.cpp |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

LGTM, thanks!

	-ss

Your patch has been merged.
Thank You
-C

Quoted 33 lines
Quoted 29 lines
src/process/process.cpp +2 -1
index 71f81b6..34dc68d 100644
@@ -86,7 +86,7 @@ static void cmdline_to_string(char *str)
 
  process::process(const char *_comm, int _pid, int _tid) : power_consumer()
  {
-	char line[4096];
+	char line[4097];
  	ifstream file;
 
  	strcpy(comm, _comm);
@@ -103,6 +103,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer()
  		file.open(line);
  		while (file) {
  			file.getline(line, 4096);
+			line[4096] = '\0';
  			if (strstr(line, "Tgid")) {
  				char *c;
  				c = strchr(line, ':');
Signature · 6 lines
1.7.10.4

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop

_______________________________________________
PowerTop mailing list
PowerTop(a)lists.01.org
https://lists.01.org/mailman/listinfo/powertop