Bug 114110

Summary: [libdisk] [patch] Disk_Names() returns a vector that is unsafe to free
Product: Base System Reporter: David Sanderson <dws>
Component: kernAssignee: Antoine Brodin <antoine>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.txt none

Description David Sanderson 2007-06-28 22:50:01 UTC
The documentation for the Disk_Names() function in libdisk(3) states:

     Disk_Names() returns `char**' with all disk's names (wd0, wd1 ...).  You
     must free each pointer, as well as the array by hand.

However, looking at the code, in FreeBSD 6 this routine returns a vector that
can be freed, but only one of the pointers in that vector can be freed, because
they all point to space in a single malloced buffer, char *disklist.  Since the pointers in the vector are sorted by the strings they point to, there is no way for the caller to know which is safe to free, and it is certainly wrong to free them all.

It would be best for Disk_Names() to return a vector according to its docs.

Fix: I'll contribute a sample new version that returns a vector that is safe to free according to the docs.

Patch attached with submission follows:
Comment 1 dfilter service freebsd_committer freebsd_triage 2008-02-15 21:19:25 UTC
antoine     2008-02-15 21:19:15 UTC

  FreeBSD src repository

  Modified files:
    lib/libdisk          disk.c 
  Log:
  - Make Disk_Names() behave as documented in libdisk(3): return an array
  of disk names, where you must free each pointer, as well as the array
  by hand. [1]
  - Destaticize "disks" in Disk_Names, it has no reasons to be static.
  
  PR:             kern/96077 [1]
  PR:             kern/114110 [1]
  MFC after:      1 month
  Approved by:    rwatson (mentor)
  
  Revision  Changes    Path
  1.128     +14 -5     src/lib/libdisk/disk.c
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 2 Antoine Brodin freebsd_committer freebsd_triage 2008-02-15 21:24:38 UTC
State Changed
From-To: open->patched

Patched in revision 1.128 of src/lib/libdisk/disk.c 


Comment 3 Antoine Brodin freebsd_committer freebsd_triage 2008-02-15 21:24:38 UTC
Responsible Changed
From-To: freebsd-bugs->antoine

Patched in revision 1.128 of src/lib/libdisk/disk.c
Comment 4 dfilter service freebsd_committer freebsd_triage 2008-03-17 19:05:42 UTC
antoine     2008-03-17 19:05:36 UTC

  FreeBSD src repository

  Modified files:        (Branch: RELENG_7)
    lib/libdisk          disk.c 
  Log:
  MFC to RELENG_7
    - Make Disk_Names() behave as documented in libdisk(3): return an array
    of disk names, where you must free each pointer, as well as the array
    by hand. [1]
    - Destaticize "disks" in Disk_Names, it has no reasons to be static.
  
    PR:             kern/96077 [1]
    PR:             kern/114110 [1]
    MFC after:      1 month
    Approved by:    rwatson (mentor)
  
  Revision   Changes    Path
  1.127.2.1  +14 -5     src/lib/libdisk/disk.c
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 5 dfilter service freebsd_committer freebsd_triage 2008-03-17 19:08:39 UTC
antoine     2008-03-17 19:08:33 UTC

  FreeBSD src repository

  Modified files:        (Branch: RELENG_6)
    lib/libdisk          disk.c 
  Log:
  MFC to RELENG_6
    - Make Disk_Names() behave as documented in libdisk(3): return an array
    of disk names, where you must free each pointer, as well as the array
    by hand. [1]
    - Destaticize "disks" in Disk_Names, it has no reasons to be static.
  
    PR:             kern/96077 [1]
    PR:             kern/114110 [1]
    MFC after:      1 month
    Approved by:    rwatson (mentor)
  
  Revision   Changes    Path
  1.125.2.2  +14 -5     src/lib/libdisk/disk.c
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 6 Antoine Brodin freebsd_committer freebsd_triage 2008-03-17 19:13:25 UTC
State Changed
From-To: patched->closed

Close: fixed in HEAD, RELENG_7 and RELENG_6. 
Thanks for the report.