Bug 195668 - Inconsistant use of strlen() + 1 in SYSCTL_OUT
Summary: Inconsistant use of strlen() + 1 in SYSCTL_OUT
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Ian Lepore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-04 03:39 UTC by Ian Lepore
Modified: 2016-01-02 04:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lepore freebsd_committer freebsd_triage 2014-12-04 03:39:20 UTC
grep in /usr/src/sys for SYSCTL_OUT.*strlen and you find 31 occurrances, 11 of which have a +1 and 20 of which don't.  It appears that adding one to account for the nullterm is correct, but I don't have time right now to followup and fix them all, so I'm opening this PR so it doesn't get forgotten.
Comment 1 commit-hook freebsd_committer freebsd_triage 2015-03-12 18:07:30 UTC
A commit references this bug:

Author: ian
Date: Thu Mar 12 18:06:31 UTC 2015
New revision: 279932
URL: https://svnweb.freebsd.org/changeset/base/279932

Log:
  Nullterminate strings returned via sysctl.

  PR:		195668

Changes:
  head/sys/vm/vm_phys.c
  head/sys/vm/vm_reserv.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-03-12 18:10:31 UTC
A commit references this bug:

Author: ian
Date: Thu Mar 12 18:09:40 UTC 2015
New revision: 279933
URL: https://svnweb.freebsd.org/changeset/base/279933

Log:
  Nullterminate strings returned via sysctl.

  PR:		195668

Changes:
  head/sys/dev/wbwd/wbwd.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-03-12 18:22:33 UTC
A commit references this bug:

Author: ian
Date: Thu Mar 12 18:22:21 UTC 2015
New revision: 279934
URL: https://svnweb.freebsd.org/changeset/base/279934

Log:
  Nullterminate strings returned via sysctl.

  PR:		195668

Changes:
  head/sys/dev/cxgbe/t4_l2t.c
  head/sys/dev/cxgbe/t4_main.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-03-14 13:01:16 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 13:00:38 UTC 2015
New revision: 279982
URL: https://svnweb.freebsd.org/changeset/base/279982

Log:
  Revert r279932; this is going to be fixed in the sbuf code instead.

  PR:		195668

Changes:
  head/sys/vm/vm_phys.c
  head/sys/vm/vm_reserv.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2015-03-14 13:02:18 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 13:02:09 UTC 2015
New revision: 279983
URL: https://svnweb.freebsd.org/changeset/base/279983

Log:
  Revert r279933; this is going to be fixed in sbuf instead.

  PR:		195668

Changes:
  head/sys/dev/wbwd/wbwd.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2015-03-14 13:05:19 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 13:04:40 UTC 2015
New revision: 279984
URL: https://svnweb.freebsd.org/changeset/base/279984

Log:
  Revert r279934, r279938; this is going to be fixed in sbuf instead.

  PR:		195668

Changes:
  head/sys/dev/cxgbe/t4_l2t.c
  head/sys/dev/cxgbe/t4_main.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-03-14 17:08:53 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 17:08:30 UTC 2015
New revision: 279993
URL: https://svnweb.freebsd.org/changeset/base/279993

Log:
  Set the SBUF_INCLUDENUL flag in sbuf_new_for_sysctl() so that sysctl
  strings returned to userland include the nulterm byte.

  Some uses of sbuf_new_for_sysctl() write binary data rather than strings;
  clear the SBUF_INCLUDENUL flag after calling sbuf_new_for_sysctl() in
  those cases.  (Note that the sbuf code still automatically adds a nulterm
  byte in sbuf_finish(), but since it's not included in the length it won't
  get copied to userland along with the binary data.)

  Remove explicit adding of a nulterm byte in a couple places now that it
  gets done automatically by the sbuf drain code.

  PR:		195668

Changes:
  head/sys/dev/cxgb/cxgb_sge.c
  head/sys/dev/cxgbe/t4_main.c
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_malloc.c
  head/sys/kern/kern_proc.c
  head/sys/kern/kern_sysctl.c
  head/sys/vm/uma_core.c
Comment 8 commit-hook freebsd_committer freebsd_triage 2015-03-14 18:12:02 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 18:11:25 UTC 2015
New revision: 279997
URL: https://svnweb.freebsd.org/changeset/base/279997

Log:
  Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
  string returned to userland is nulterminated.

  PR:		195668

Changes:
  head/sys/netinet/tcp_hostcache.c
Comment 9 commit-hook freebsd_committer freebsd_triage 2015-03-14 18:43:09 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 18:42:31 UTC 2015
New revision: 279999
URL: https://svnweb.freebsd.org/changeset/base/279999

Log:
  Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
  string returned to userland is nulterminated.

  PR:           195668

Changes:
  head/sys/kern/sched_ule.c
Comment 10 commit-hook freebsd_committer freebsd_triage 2015-03-14 18:47:10 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 18:46:33 UTC 2015
New revision: 280000
URL: https://svnweb.freebsd.org/changeset/base/280000

Log:
  Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
  string returned to userland is nulterminated.

  PR:           195668

Changes:
  head/sys/kern/kern_fail.c
Comment 11 commit-hook freebsd_committer freebsd_triage 2015-03-14 21:40:22 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 21:40:02 UTC 2015
New revision: 280006
URL: https://svnweb.freebsd.org/changeset/base/280006

Log:
  Use SYSCTL_OUT_STR() to return strings.

  PR:		195668

Changes:
  head/sys/kern/subr_bus.c
  head/sys/kern/subr_param.c
Comment 12 commit-hook freebsd_committer freebsd_triage 2015-03-14 21:41:23 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 21:40:25 UTC 2015
New revision: 280007
URL: https://svnweb.freebsd.org/changeset/base/280007

Log:
  Use SYSCTL_OUT_STR() to return strings.

  PR:		195668

Changes:
  head/sys/xen/xenbus/xenbusb.c
Comment 13 commit-hook freebsd_committer freebsd_triage 2015-03-14 21:41:24 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 21:40:33 UTC 2015
New revision: 280008
URL: https://svnweb.freebsd.org/changeset/base/280008

Log:
  Use SYSCTL_OUT_STR() to return strings.

  PR:		195668

Changes:
  head/sys/dev/usb/net/usb_ethernet.c
Comment 14 commit-hook freebsd_committer freebsd_triage 2015-03-14 21:41:25 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 21:40:52 UTC 2015
New revision: 280009
URL: https://svnweb.freebsd.org/changeset/base/280009

Log:
  Use SYSCTL_OUT_STR() to return strings.

  PR:		195668

Changes:
  head/sys/mips/rmi/dev/iic/at24co2n.c
Comment 15 commit-hook freebsd_committer freebsd_triage 2015-03-14 21:41:26 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 21:41:01 UTC 2015
New revision: 280010
URL: https://svnweb.freebsd.org/changeset/base/280010

Log:
  Use SYSCTL_OUT_STR() to return strings.

  PR:		195668

Changes:
  head/sys/net80211/ieee80211_freebsd.c
Comment 16 commit-hook freebsd_committer freebsd_triage 2015-03-14 22:32:34 UTC
A commit references this bug:

Author: ian
Date: Sat Mar 14 22:32:16 UTC 2015
New revision: 280011
URL: https://svnweb.freebsd.org/changeset/base/280011

Log:
  Use sysctl_handle_string() and the sbuf printf routines instead of large
  stack-allocated buffers and snprintf().

  PR:		195668

Changes:
  head/sys/dev/iscsi_initiator/isc_sm.c
Comment 17 commit-hook freebsd_committer freebsd_triage 2015-03-15 00:36:44 UTC
A commit references this bug:

Author: ian
Date: Sun Mar 15 00:36:09 UTC 2015
New revision: 280015
URL: https://svnweb.freebsd.org/changeset/base/280015

Log:
  Include the nulterm byte in the sysctl string.

  PR:		195668

Changes:
  head/sys/kern/kern_cons.c
Comment 18 commit-hook freebsd_committer freebsd_triage 2015-03-15 00:39:46 UTC
A commit references this bug:

Author: ian
Date: Sun Mar 15 00:39:19 UTC 2015
New revision: 280016
URL: https://svnweb.freebsd.org/changeset/base/280016

Log:
  Add a nulterm byte to the returned sysctl string.

  PR:		195668

Changes:
  head/sys/kern/subr_prf.c
Comment 19 Glen Barber freebsd_committer freebsd_triage 2015-07-08 18:32:12 UTC
To originators/assignees of this PR:

A commit to the tree references this PR, however the PR is still in a non-closed state.

Please review this PR and close as appropriate, or if closing the PR requires a merge to stable/10, please let re@ know as soon as possible.

Thank you.

Glen
Comment 20 Ian Lepore freebsd_committer freebsd_triage 2016-01-02 04:03:38 UTC
Long overdue closing of this bug.  Several more commits were done that neglected to cite the PR number.  As far as I know the last commit related to this was r280355 on 2015/03/22.