summaryrefslogtreecommitdiff
blob: 23a0ce61834818728fdd1fe0812a8b1624e35739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Fix buffer overflows

https://bugs.gentoo.org/show_bug.cgi?id=338936

Patch written by Kevin Pyle
--- bbacpi.cc
+++ bbacpi.cc
@@ -167,7 +167,7 @@
   if (ret = (fp = fopen(name, "r"))) {
     char buffer[100];
     char present[20];
-    fgets(buffer,128,fp);
+    fgets(buffer, sizeof(buffer),fp);
     sscanf(buffer,"present:                 %s", present);
     if (strncmp(present, "yes", 3) != 0) {
       fprintf(stderr, "Device %s not present.\n", device);
@@ -195,7 +195,7 @@
     {
       /* Read data in any order */
       found = 0;
-      while (found < 11 && (fgets(buffer, 63, fp) != NULL)) {
+      while (found < 11 && (fgets(buffer, sizeof(buffer), fp) != NULL)) {
 	/* Present */
 	if (strncmp(buffer, "present:", 7) == 0 
 	    || strncmp(buffer, "Present:", 7) == 0) {
@@ -277,7 +277,7 @@
       {
 	/* Read data in any order */
 	found = 0;
-	while (found < 11  && (fgets(buffer, 63, fp) != NULL)) {
+	while (found < 11  && (fgets(buffer, sizeof(buffer), fp) != NULL)) {
 	  /* Present */
 	  if (strncmp(buffer, "present:", 7) == 0 
 	      || strncmp(buffer, "Present:", 7) == 0) {
@@ -361,7 +361,7 @@
   if ((fp = fopen(names.temptrip, "r")))
     {
       found = 0;
-      while (found < 2 && (fgets(buffer,128,fp) != NULL)) {
+      while (found < 2 && (fgets(buffer, sizeof(buffer),fp) != NULL)) {
 	/* Critical */
 	if (strncmp(buffer, "critical", 8) == 0 
 	    || strncmp(buffer, "Critical", 8) == 0) {
@@ -425,7 +425,7 @@
 	if  (file_status.st_mtime != last_mtime)
 	  {
 	    found = 0;
-	    while (found < 4 && (fgets(buffer, 63, fp) != NULL)) {
+	    while (found < 4 && (fgets(buffer, sizeof(buffer), fp) != NULL)) {
 	      /* Charging state */
 	      if (strncmp(buffer, "charging state:", 15) == 0 
 		  || strncmp(buffer, "Charging State:", 15) == 0) {
@@ -463,7 +463,7 @@
 	if  (file_status.st_mtime != last_mtime)
 	  {
 	    found = 0;
-	    while (found < 4 && (fgets(buffer, 63, fp) != NULL)) {
+	    while (found < 4 && (fgets(buffer, sizeof(buffer), fp) != NULL)) {
 	      /* Charging state */
 	      if (strncmp(buffer, "charging state:", 15) == 0 
 		  || strncmp(buffer, "Charging State:", 15) == 0) {
@@ -497,7 +497,7 @@
   if ((fp = fopen(names.adapter, "r")))
     {
       found = 0;
-      while (found < 1 && (fgets(buffer, 63,fp) != NULL)) {
+      while (found < 1 && (fgets(buffer, sizeof(buffer),fp) != NULL)) {
 	if (strncmp(buffer, "state:", 6) == 0 
 	    || strncmp(buffer, "State:", 6) == 0) {
 	  sscanf(buffer+offset,"%s", adapter.state);
@@ -511,7 +511,7 @@
   if ((fp = fopen(names.temperature, "r")))
     {
       found = 0;
-      while (found < 1 && (fgets(buffer, 63,fp) != NULL)) {
+      while (found < 1 && (fgets(buffer, sizeof(buffer),fp) != NULL)) {
 	if (strncmp(buffer, "temperature:", 12) == 0 
 	    || strncmp(buffer, "Temperature:", 12) == 0) {
 	  sscanf(buffer+offset,"%u", &temperature.celcius);