From owner-freebsd-bugs@FreeBSD.ORG Fri May 21 05:40:12 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7089416A4E0 for ; Fri, 21 May 2004 05:40:12 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 61AF043D54 for ; Fri, 21 May 2004 05:40:12 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i4LCeCSJ053605 for ; Fri, 21 May 2004 05:40:12 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i4LCeCQ4053604; Fri, 21 May 2004 05:40:12 -0700 (PDT) (envelope-from gnats) Resent-Date: Fri, 21 May 2004 05:40:12 -0700 (PDT) Resent-Message-Id: <200405211240.i4LCeCQ4053604@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Liam J. Foy" Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8CBA216A4CE for ; 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 ; 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" To: "FreeBSD gnats submit" X-Send-Pr-Version: gtk-send-pr 0.3.3 Subject: bin/66988: [Patch] apm.c check validation of the returned values X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2004 12:40:12 -0000 >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: