misc/69376: sysutils/healthd: conversion bug

Andriy Gapon avg at icyb.net.ua
Wed Jul 21 04:30:25 PDT 2004

>Number:         69376
>Category:       misc
>Synopsis:       sysutils/healthd: conversion bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 21 11:30:24 GMT 2004
>Originator:     Andriy Gapon
>Release:        FreeBSD 4.10 or 5.2.1 i386
FreeBSD 4.10 or 5.2.1 i386
      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.
      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

      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.

More information about the freebsd-bugs mailing list