NetBSD Problem Report #30034

From mange@freemail.hu  Fri Apr 22 18:35:00 2005
Return-Path: <mange@freemail.hu>
Received: from pne-smtpout1-sn2.hy.skanova.net (pne-smtpout1-sn2.hy.skanova.net [81.228.8.83])
	by narn.netbsd.org (Postfix) with ESMTP id 487A463B11A
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 22 Apr 2005 18:35:00 +0000 (UTC)
Message-Id: <200504221836.j3MIa3Up001719@zemdatav.stor.no-ip.org>
Date: Fri, 22 Apr 2005 20:36:03 +0200 (CEST)
From: Magnus Henoch <mange@freemail.hu>
Reply-To: Magnus Henoch <mange@freemail.hu>
To: gnats-bugs@netbsd.org
Subject: Logic error in determining battery type on macppc
X-Send-Pr-Version: 3.95

>Number:         30034
>Category:       port-macppc
>Synopsis:       Logic error in determining battery type on macppc
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    briggs
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 22 18:36:00 +0000 2005
>Closed-Date:    Wed Apr 27 16:42:43 +0000 2005
>Last-Modified:  Wed Apr 27 16:42:43 +0000 2005
>Originator:     Magnus Henoch
>Release:        NetBSD 3.99.3
>Organization:

>Environment:


System: NetBSD zemdatav 3.99.3 NetBSD 3.99.3 (IBOOKFAN) #11: Fri Apr 22 19:38:27 CEST 2005 magnus@zemdatav:/usr/src/sys/arch/macppc/compile/IBOOKFAN macppc
Architecture: powerpc
Machine: macppc
>Description:

	On my iBook G4 of 1 GHz, the battery type is incorrectly
	detected, which means that data about battery life is bogus.
>How-To-Repeat:

	Run "apm" on affected hardware.  Output:

	Battery charge state: CRITICAL
	Battery remaining: 0 percent (0 minutes)
	A/C adapter state: connected
	Power management enabled

	regardless of actual battery state.
>Fix:


	Apply the following patch to
	src/sys/arch/macppc/dev/pm_direct.c.  The direct cause of the
	problem is that the compatibility list on which strinlist is
	used has a zero-length string at the end, which means that the
	first 0 bytes of the two strings are compared.

--- pm_direct.c	02 Feb 2005 04:03:49 +0100	1.25
+++ pm_direct.c	22 Apr 2005 19:44:59 +0200	
@@ -251,16 +251,21 @@
 {
 }

+/*
+ * Search for targ in list.  list is an area of listlen bytes
+ * containing null-terminated strings.
+ */
 static int
 strinlist(char *targ, char *list, int listlen)
 {
 	char	*str;
 	int	sl;
+	int	targlen = strlen(targ);

 	str = list;
 	while (listlen > 0) {
 		sl = strlen(str);
-		if (strncmp(targ, str, sl) == 0)
+		if (sl == targlen && strncmp(targ, str, sl) == 0)
 			return 1;
 		str += sl+1;
 		listlen -= sl+1;

>Release-Note:

>Audit-Trail:
From: Allen Briggs <briggs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/30034 CVS commit: src/sys/arch/macppc/dev
Date: Wed, 27 Apr 2005 16:41:54 +0000 (UTC)

 Module Name:	src
 Committed By:	briggs
 Date:		Wed Apr 27 16:41:54 UTC 2005

 Modified Files:
 	src/sys/arch/macppc/dev: pm_direct.c

 Log Message:
 Correctly match battery types.  Old function would end up matching a
 zero-length string.  Noted in PR port-macppc/30034 by Magnus Henoch.
 Patched as in the PR.


 To generate a diff of this commit:
 cvs rdiff -r1.25 -r1.26 src/sys/arch/macppc/dev/pm_direct.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: port-macppc-maintainer->briggs
Responsible-Changed-By: briggs@netbsd.org
Responsible-Changed-When: Wed, 27 Apr 2005 16:42:43 +0000
Responsible-Changed-Why:
I took it.


State-Changed-From-To: open->closed
State-Changed-By: briggs@netbsd.org
State-Changed-When: Wed, 27 Apr 2005 16:42:43 +0000
State-Changed-Why:
Patched as in the PR.  Thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.