Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jul 2004 11:23:06 GMT
From:      Andriy Gapon <avg@icyb.net.ua>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/69376: sysutils/healthd: conversion bug
Message-ID:  <200407211123.i6LBN6G2093139@www.freebsd.org>
Resent-Message-ID: <200407211130.i6LBUOGc024806@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         69376
>Category:       misc
>Synopsis:       sysutils/healthd: conversion bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 21 11:30:24 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Andriy Gapon
>Release:        FreeBSD 4.10 or 5.2.1 i386
>Organization:
>Environment:
FreeBSD 4.10 or 5.2.1 i386
healthd-0.7.7
>Description:
      healthd may return some unexpected negative values when using SMB method to get hardware readings. this happens because of confusing type usage in getMB-smb.c, function ReadByte():

static int
ReadByte(int addr) {
  unsigned char count = 0;
  struct smbcmd cmd;
  char ret;
..
  return (unsigned int)ret;
}

if char type is signed (which is the case for i386) and if ret variable contains a negative value (corresponding to 0x80-0xFF range) then this function will return the same negative value, only as int, despite an obvious, but obviously incorrect attempt to cast return value to unsigned type. Value returned from this function  in some cases is assigned to unsigned char variable which makes things sane, but in other cases it is used directly in calculations, so this problem can not observed for all parameters. the most likely candidate is 3.3 volatge.
>How-To-Repeat:
      1. compile healthd with SMB support and run it on a SMB HWM-enabled system, to ensure that SMB is used run healthd with -S option, also use -d option to get debug output
2. check +3.3V voltage value, you will negative value (about -0.70) instead of a correct value


>Fix:
      change return statement in ReadByte for correct casting to unsigned byte:

- return (unsigned int)ret;
+ return (unsigned char)ret;

better yet, change interface to appropriate one that would return unsigned char instead of too wide int.
>Release-Note:
>Audit-Trail:
>Unformatted:



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