From liamfoy@sepulcrum.org  Fri May 21 05:33:19 2004
Return-Path: <liamfoy@sepulcrum.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8CBA216A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 May 2004 05:33:19 -0700 (PDT)
Received: from moutvdomng.kundenserver.de (moutvdom.kundenserver.de [212.227.126.249])
	by mx1.FreeBSD.org (Postfix) with ESMTP id F409543D2F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 May 2004 05:33:18 -0700 (PDT)
	(envelope-from liamfoy@sepulcrum.org)
Received: from [212.227.126.221] (helo=mrvdomng.kundenserver.de)
	by moutvdomng.kundenserver.de with esmtp (Exim 3.35 #1)
	id 1BR9Cw-0001Hy-00
	for FreeBSD-gnats-submit@freebsd.org; Fri, 21 May 2004 14:33:02 +0200
Received: from [217.42.173.195] (helo=liamfoy.ath.cx)
	by mrvdomng.kundenserver.de with esmtp (Exim 3.35 #1)
	id 1BR9Cv-0006xM-00
	for FreeBSD-gnats-submit@freebsd.org; Fri, 21 May 2004 14:33:01 +0200
Message-Id: <1085142727.0@liamfoy.ath.cx>
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: [Patch] apm.c check validation of the returned values
X-Send-Pr-Version: gtk-send-pr 0.3.3 
X-GNATS-Notify:

>Number:         66988
>Category:       bin
>Synopsis:       [patch] apm(8) 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:  Sat May 24 19:33:14 UTC 2008
>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:
