Bug 179832 - manual page of mac_from_text suggests incorrect freeing of mac_t type
Summary: manual page of mac_from_text suggests incorrect freeing of mac_t type
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: Kyle Evans
URL:
Keywords: easy
Depends on:
Blocks:
 
Reported: 2013-06-22 09:20 UTC by Priit Järv
Modified: 2026-01-20 04:20 UTC (History)
3 users (show)

See Also:
kevans: mfc-stable15+
kevans: mfc-stable14+
kevans: mfc-stable13-


Attachments
mac_free.3 patch and mac_text.3 patch (781 bytes, patch)
2021-09-30 07:20 UTC, Felix Johnson
felix.the.red: maintainer-approval? (felix.the.red)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Priit Järv 2013-06-22 09:20:00 UTC
manual page of mac_from_text(3) notes that the allocated storage should be freed with free(). I strongly suspect this is incorrect, as the type mac_t points to a structure which itself contains a pointer.

It seems this was introduced in svn rev 122777 where "mac_free(3)" was changed to "free(3)". It seems the specific change was meant for the mac_to_text() function call (a char* pointer indeed should be freed with free()).

Reported for 9.1-RELEASE but still present in head/stable.

Fix: 

Replace the text "which must later be freed with free(3)" with "which must later be freed with mac_free(3)". Additionally, it may be useful to mention in the next section that the text pointer allocated by mac_to_text() should be freed with free() - that seems to have been the intent of commit r122777.
How-To-Repeat: man mac_text
Comment 1 Tom Rhodes freebsd_committer freebsd_triage 2014-01-08 20:10:21 UTC
Responsible Changed
From-To: freebsd-doc->rwatson

Over to Robert.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:16 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 3 Felix Johnson 2021-09-30 07:20:13 UTC
Created attachment 228276 [details]
mac_free.3 patch and mac_text.3 patch

For mac_text(3), change reference to free(3) back to mac_free(3) for mac_from_text.

For mac_free(3), change a variable type from mac_3 to mac_t.
Comment 4 Kyle Evans freebsd_committer freebsd_triage 2025-10-26 15:15:11 UTC
Moving to a base system component so that I can set mfc flags (?)
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-10-26 15:15:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=081218b7a2006e5b6783e51f66fd751871ac1272

commit 081218b7a2006e5b6783e51f66fd751871ac1272
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-10-26 15:10:34 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-10-26 15:13:21 +0000

    libc: fix description issues in mac_text(3)/mac_free(3)

    mac_text(3) as-written would seem to indicate that a `mac_t` should be
    freed with free(3), but this isn't the case.  One can derive from
    context from when the change was introduced and COMPATIBILITY that this
    was intended to talk about *text in `mac_to_text`, so move the comment
    there.

    PR:             179832
    Co-authored-by: Priit Järv <priit cc ttu ee>
    MFC after:      3 days

 lib/libc/posix1e/mac_free.3 | 4 ++--
 lib/libc/posix1e/mac_text.3 | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-01-20 04:10:20 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b5b3bf57e9fb35f8445b92e638a9fe351490825c

commit b5b3bf57e9fb35f8445b92e638a9fe351490825c
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-10-26 15:10:34 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-01-20 04:04:08 +0000

    libc: fix description issues in mac_text(3)/mac_free(3)

    mac_text(3) as-written would seem to indicate that a `mac_t` should be
    freed with free(3), but this isn't the case.  One can derive from
    context from when the change was introduced and COMPATIBILITY that this
    was intended to talk about *text in `mac_to_text`, so move the comment
    there.

    PR:             179832
    Co-authored-by: Priit Järv <priit cc ttu ee>

    (cherry picked from commit 081218b7a2006e5b6783e51f66fd751871ac1272)

 lib/libc/posix1e/mac_free.3 | 4 ++--
 lib/libc/posix1e/mac_text.3 | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-01-20 04:10:25 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f00ebc7eb3a65494749fb85b3fd8f27ea09296ae

commit f00ebc7eb3a65494749fb85b3fd8f27ea09296ae
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-10-26 15:10:34 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-01-20 04:05:37 +0000

    libc: fix description issues in mac_text(3)/mac_free(3)

    mac_text(3) as-written would seem to indicate that a `mac_t` should be
    freed with free(3), but this isn't the case.  One can derive from
    context from when the change was introduced and COMPATIBILITY that this
    was intended to talk about *text in `mac_to_text`, so move the comment
    there.

    PR:             179832
    Co-authored-by: Priit Järv <priit cc ttu ee>

    (cherry picked from commit 081218b7a2006e5b6783e51f66fd751871ac1272)

 lib/libc/posix1e/mac_free.3 | 4 ++--
 lib/libc/posix1e/mac_text.3 | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
Comment 8 Kyle Evans freebsd_committer freebsd_triage 2026-01-20 04:20:39 UTC
Thanks!