Bug 206758 - [PATCH] Uninitalized variable in atrun
Summary: [PATCH] Uninitalized variable in atrun
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.2-RELEASE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Enji Cooper
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-01-30 13:10 UTC by Christoph Schönweiler
Modified: 2016-03-12 19:13 UTC (History)
4 users (show)

See Also:
ngie: mfc-stable10+
ngie: mfc-stable9+


Attachments
Patch for the atrun source (302 bytes, patch)
2016-01-30 13:10 UTC, Christoph Schönweiler
no flags Details | Diff
Fix ncpu type (376 bytes, patch)
2016-01-30 15:23 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Schönweiler 2016-01-30 13:10:33 UTC
Created attachment 166300 [details]
Patch for the atrun source

The atrun utility needs the number of CPUs for calculating the load limit. If the average load is lower than that limit the next pending batch job is started.

The number of CPUs is retrieved with an call to 'sysctlbyname'. This subroutine writes the number (which is an integer) to the "ncpu" variable. The variable ist defined as size_t, which is an unsigned integer but is never initalized. So the result of this operation is undefined.

The value of ncpu after calling sysctlbyname:
current version: 34359738369
patched version: 1
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2016-01-30 15:23:48 UTC
Created attachment 166306 [details]
Fix ncpu type

I believe that you found the issue, but your fix is not right.  E.g., the problem of invalid ncpu value would be still present on the big-endian LP64 machines.

The fix is to use int type, consistent with the type expected by the hw.ncpu MIB.
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-01-30 17:54:57 UTC
A commit references this bug:

Author: ngie
Date: Sat Jan 30 17:54:18 UTC 2016
New revision: 295079
URL: https://svnweb.freebsd.org/changeset/base/295079

Log:
  Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on
  64-bit architectures where sizeof(int) != sizeof(size_t).

  MFC after: 1 week
  PR: 206758
  Reported by: Christoph Sch?nweiler <public2016@hauptsignal.at>
  Submitted by: kib
  Sponsored by: EMC / Isilon Storage Division

Changes:
  head/libexec/atrun/atrun.c
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2016-01-30 17:55:42 UTC
Thank you for the submission/patch. I proved that it was doing the wrong thing by adding a printf(3) after the sysctlbyname call on my amd64 VM.
Comment 4 op 2016-02-13 13:52:48 UTC
Any update with this patch on MFC to 10-STABLE?
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-03-12 19:10:06 UTC
A commit references this bug:

Author: ngie
Date: Sat Mar 12 19:09:52 UTC 2016
New revision: 296756
URL: https://svnweb.freebsd.org/changeset/base/296756

Log:
  MFC r295079:

  Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on
  64-bit architectures where sizeof(int) != sizeof(size_t).

  PR: 206758

Changes:
_U  stable/10/
  stable/10/libexec/atrun/atrun.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2016-03-12 19:12:10 UTC
A commit references this bug:

Author: ngie
Date: Sat Mar 12 19:11:45 UTC 2016
New revision: 296757
URL: https://svnweb.freebsd.org/changeset/base/296757

Log:
  MFstable/10 r296756:

  MFC r295079:

  Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on
  64-bit architectures where sizeof(int) != sizeof(size_t).

  PR: 206758

Changes:
_U  stable/9/
_U  stable/9/libexec/atrun/
  stable/9/libexec/atrun/atrun.c
Comment 7 Enji Cooper freebsd_committer freebsd_triage 2016-03-12 19:13:19 UTC
(In reply to op from comment #4)

I just MFCed it to stable/10.