All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: Re: [Powertop] [bugreport] crash on powertop --debug --html=file.html
Date: Fri, 06 Jul 2012 12:00:04 +0300	[thread overview]
Message-ID: <20120706090004.GA4186@swordfish> (raw)
In-Reply-To: b127e9b0-82ab-46df-b76e-9347e7543867@email.android.com

[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]

Hi,

Could you please give it a try? (just a bunch of suspects).
If it fails, it'd be nice to see valgrind output.

---

 src/devlist.cpp | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/devlist.cpp b/src/devlist.cpp
index 93f2081..e65981e 100644
--- a/src/devlist.cpp
+++ b/src/devlist.cpp
@@ -89,7 +89,6 @@ void collect_open_devices(void)
 	}
 	target->resize(0);
 
-
 	dir = opendir("/proc/");
 	if (!dir)
 		return;
@@ -105,7 +104,7 @@ void collect_open_devices(void)
 		if (strcmp(entry->d_name, "self") == 0)
 			continue;
 
-		sprintf(filename, "/proc/%s/fd/", entry->d_name);
+		snprintf(filename, 4095, "/proc/%s/fd/", entry->d_name);
 
 		dir2 = opendir(filename);
 		if (!dir2)
@@ -113,12 +112,14 @@ void collect_open_devices(void)
 		while (1) {
 			int ret;
 			struct devuser * dev;
+			std::string comm;
+
 			entry2 = readdir(dir2);
 			if (!entry2)
 				break;
 			if (entry2->d_name[0] == '.')
 				continue;
-			sprintf(filename, "/proc/%s/fd/%s", entry->d_name, entry2->d_name);
+			snprintf(filename, 4095, "/proc/%s/fd/%s", entry->d_name, entry2->d_name);
 			memset(link, 0, 4096);
 			ret = readlink(filename, link, 4095);
 			if (ret < 0)
@@ -147,10 +148,14 @@ void collect_open_devices(void)
 					continue;
 				dev->pid = strtoull(entry->d_name, NULL, 10);
 				strncpy(dev->device, link, 251);
-				sprintf(filename, "/proc/%s/comm", entry->d_name);
-				strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
+				dev->device[251] = 0x00;
+				comm = read_sysfs_string("/proc/%s/comm", entry->d_name);
+				if (comm.empty())
+					dev->comm[0] = 0x00;
+				else
+					strncpy(dev->comm, read_sysfs_string("/proc/%s/comm", entry->d_name).c_str(), 31);
+				dev->comm[31] = 0x00;
 				target->push_back(dev);
-
 			}
 		}
 		closedir(dir2);


             reply	other threads:[~2012-07-06  9:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06  9:00 Sergey Senozhatsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-07-01 20:07 [Powertop] [bugreport] crash on powertop --debug --html=file.html 
2012-07-01 18:13 Sergey Senozhatsky
2012-07-01 13:46 
2012-06-27 16:37 Sergey Senozhatsky
2012-06-27 16:32 Sergey Senozhatsky
2012-06-27 13:57 Arjan van de Ven
2012-06-27  9:42 
2012-06-27  8:06 Sergey Senozhatsky
2012-06-26 19:09 
2012-06-26 18:50 Chris Ferron
2012-06-26 18:42 Chris Ferron
2012-06-26 15:10 

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120706090004.GA4186@swordfish \
    --to=powertop@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.