Control: severity -1 important

Hi!

This might deserve to be serious instead of important, but I'll leave
that up to the maintainers. It would be nice to fix it for Jessie,
though, as both severities should be good candidates for acceptance.

On Fri, 2014-09-26 at 10:29:09 +0200, Gergely Risko wrote:
> Package: acpitool
> Version: 0.5.1-3
> Tags: patch

> While parsing /proc/acpi/wakeup, src/acpitool.cpp assumes that lines are
> maximum 39 char long (40 including the terminating NUL character at the
> end of C strings).
> 
> Since I have a line in /proc/acpi/wakeup that is exactly 40 char long,
> the tool doesn't work (it hangs up when it hits that line, consuming
> 100% CPU forever).

Yeah, I've got the same problem with lines such as:

,---
LID       S3    *enabled   platform:PNP0C0D:00
SLPB      S3    *enabled   platform:PNP0C0E:00
`---

and acpitool -w (or -e) getting stuck like this:

,---
$ acpitool -w
   Device       S-state   Status   Sysfs node
  ---------------------------------------
  1. LID          S3    *enabled   platform:PNP0C0D:00
  2. SLPB         S3    *enabled   platform:PNP0C0E:0
^C
`---

> The attached patch changes this behavior to assume maximum 79 char long
> lines by increasing the buffer size to 80.

I'm attaching a patch I prepared before noticing this bug report,
switching that code to dynamically allocated types instead, which
should be more future-proof anyway.

Thanks,
Guillem
From 2f16822b9487a951ac898fd6703a7f8c7cd4ce06 Mon Sep 17 00:00:00 2001
From: Guillem Jover <[email protected]>
Date: Sat, 15 Nov 2014 11:59:37 +0100
Subject: [PATCH] Do not assume fixed line lengths for /proc/acpi/wakeup file

The lines in that file might be equal or longer than 40 characters, which
means that the getline() call will truncate them, possibly at the wrong
place, and then be unable to proceed, as subsequent calls will get stuck
waiting for input that is not coming.
---
 src/acpitool.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/acpitool.cpp b/src/acpitool.cpp
index f3beeca..e85a7c1 100644
--- a/src/acpitool.cpp
+++ b/src/acpitool.cpp
@@ -416,7 +416,8 @@ int Do_Fan_Info(int verbose)
 int Show_WakeUp_Devices(int verbose)
 {
     ifstream file_in;
-    char *filename, str[40];
+    char *filename;
+    string str;
     
     filename = "/proc/acpi/wakeup";
     
@@ -437,14 +438,14 @@ int Show_WakeUp_Devices(int verbose)
     }
     else
     {
-	file_in.getline(str, 40);           // first line are just headers //
+	getline(file_in, str);           // first line are just headers //
 	cout<<"   "<<str<<endl;
 	cout<<"  ---------------------------------------"<<endl;
         int t = 1;
 	while(!file_in.eof())
 	{
-	    file_in.getline(str, 40);
-	    if (strlen(str)!=0)                     // avoid printing last empty line //
+	    getline(file_in, str);
+	    if (str.length()!=0)                     // avoid printing last empty line //
 	    {
 		cout<<"  "<<t<<". "<<str<<endl;
 		t++;
-- 
2.1.3

Reply via email to