Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 May 2004 13:32:07 +0100
From:      "Liam J. Foy" <liamfoy@sepulcrum.org>
To:        "FreeBSD gnats submit" <FreeBSD-gnats-submit@FreeBSD.org>
Subject:   bin/66988: [Patch] apm.c check validation of the returned values
Message-ID:  <1085142727.0@liamfoy.ath.cx>
Resent-Message-ID: <200405211240.i4LCeCQ4053604@freefall.freebsd.org>

index | next in thread | raw e-mail


>Number:         66988
>Category:       bin
>Synopsis:       [Patch] apm.c check validation of the returned values
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 21 05:40:11 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Liam J. Foy
>Release:        FreeBSD 5.2-RELEASE i386
>Organization:
Sepulcrum 
>Environment:


System: FreeBSD 5.2-RELEASE #2: Mon Mar 29 17:52:08 BST 2004
    liamfoy@:/usr/obj/usr/src/sys/Ecthelion



>Description:


The current apm code will check the if the values are valid when the user prints all the information. It does not however check single ones, such as if the user does apm -l. apm -l could lead to a result of -1, which is not an error but an invalid value. The same goes for the rest apm -as etc. The patch will validiate them, and print them depending on outcome.


>How-To-Repeat:





>Fix:


--- apm.diff begins here ---
--- /usr/src/usr.sbin/apm/apm.c	Thu May 20 20:30:57 2004
+++ /hd2/apm.c	Fri May 21 12:06:48 2004
@@ -496,15 +496,33 @@
 		if (all_info)
 			print_all_info(fd, &info, bioscall_available);
 		if (ac_status)
-			printf("%d\n", info.ai_acline);
+			if(info.ai_acline == 255)
+				printf("unknown (255)\n");
+			else if(info.ai_acline > 1)
+					printf("invalid value 0x%x (%d)\n", info.ai_acline, info.ai_acline);
+			else
+				printf("%d\n", info.ai_acline);
 		if (batt_status)
-			printf("%d\n", info.ai_batt_stat);
+			if(info.ai_batt_stat == 255)
+				printf("unknown (255)\n");
+			else if(info.ai_batt_stat > 3)
+					printf("invalid value 0x%x (%d)\n", info.ai_batt_stat, info.ai_batt_stat);
+			else	
+				printf("%d\n", info.ai_batt_stat);
 		if (batt_life)
-			printf("%d\n", info.ai_batt_life);
+			if(info.ai_batt_life == 255)
+				printf("unknown (255)\n");
+			else if(info.ai_batt_life >= 0 && info.ai_batt_life <= 100)
+					printf("%d\n", info.ai_batt_life);
+			else
+				printf("invalid value 0x%x (%d)\n", info.ai_batt_life, info.ai_batt_life);
 		if (apm_status)
 			printf("%d\n", info.ai_status);
 		if (batt_time)
-			printf("%d\n", info.ai_batt_time);
+			if(info.ai_batt_time == -1)
+				printf("unknown (-1)\n");
+			else
+				printf("%d\n", info.ai_batt_time);
 		if (display != -1)
 			apm_display(fd, display);
 	}
--- apm.diff ends here ---



>Release-Note:
>Audit-Trail:
>Unformatted:


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1085142727.0>