Bug 136669 - [libc] [patch] setmode(3) should always set errno on error
Summary: [libc] [patch] setmode(3) should always set errno on error
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Pedro F. Giffuni
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-12 00:00 UTC by Yair K.
Modified: 2015-03-23 19:46 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (3.29 KB, patch)
2009-07-12 00:00 UTC, Yair K.
no flags Details | Diff
Patch based on NetBSD (2.67 KB, patch)
2015-02-21 16:59 UTC, Pedro F. Giffuni
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yair K. 2009-07-12 00:00:06 UTC
The setmode() function doesn't always set errno on error. The attached patch pulls rev 1.31 from NetBSD[1] to fix this. Notes:

A. OpenBSD[2] and NetBSD have slightly different error returns for octal mode errors. OpenBSD always returns ERANGE, while NetBSD returns EINVAL unless strtol returned ERANGE. The attached patch follows the OpenBSD policy.

B. The patch uses a slightly different definition for addcmd from NetBSD: (BITCMD *, char, mode_t, mode_t, mode_t) instead of (BITCMD *, mode_t, mode_t, mode_t, mode_t). It's pretty obvious from the context and use that op is only a char. Also, we change the types of the local vars in addcmd() appropriately to match the function definition.

C. Comments from rev 1.15[3] are added since they are more accurate after that change (which was imported to FreeBSD in the past), and reduce any future diffs. However, spelling error was corrected.

[1] http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setmode.c.diff?r1=1.30&r2=1.31&only_with_tag=MAIN
[2] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/gen/setmode.c?rev=1.20;content-type=text%2Fplain
[3] http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setmode.c.diff?r1=1.14&r2=1.15&only_with_tag=MAIN

Fix: See attached patch.

Patch attached with submission follows:
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-02-21 16:59:41 UTC
Created attachment 153280 [details]
Patch based on NetBSD

I would prefer to take only the NetBSD approach. We can check later if we should simplify it like OpenBSD did.
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-02-21 17:00:05 UTC
Grab PR.
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-02-22 20:17:44 UTC
A commit references this bug:

Author: pfg
Date: Sun Feb 22 20:16:45 UTC 2015
New revision: 279186
URL: https://svnweb.freebsd.org/changeset/base/279186

Log:
  setmode(3): Make sure that setmode sets errno on failure.

  Our man page already documented this partially but now
  we have some consistent behavior.

  PR:		136669
  Obtained from:	NetBSD (CVS rev. 1.31, 1.33)
  Relnotes:	yes
  MFC after:	3 weeks

Changes:
  head/lib/libc/gen/setmode.3
  head/lib/libc/gen/setmode.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-03-23 19:44:52 UTC
A commit references this bug:

Author: pfg
Date: Mon Mar 23 19:44:20 UTC 2015
New revision: 280392
URL: https://svnweb.freebsd.org/changeset/base/280392

Log:
  MFC	r279186:
  setmode(3): Make sure that setmode sets errno on failure.

  Our man page already documented this partially but now
  we provide more consistent behavior.

  PR:		136669
  Obtained from:	NetBSD (CVS rev. 1.31, 1.33)
  Relnotes:	yes

Changes:
_U  stable/10/
  stable/10/lib/libc/gen/setmode.3
  stable/10/lib/libc/gen/setmode.c
Comment 5 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-03-23 19:46:23 UTC
Committed and MFC'd.

Thanks!