History log of /openbsd-current/usr.bin/mail/lex.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.43 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.42 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.41 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.40 16-Sep-2018 millert

Replace the local getname() and getuserid() functions with calls
to user_from_uid(3) and uid_from_user(3). This requires sprinkling
const in a few places to match the return value of user_from_uid(3).
OK tb@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.39 16-Oct-2015 mmcc

Modernize allocation by:

* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported

ok beck@, jung@, millert@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.38 26-Oct-2014 guenther

Prefer mkostemp(O_CLOEXEC) over mkstemp()+fcntl(F_SETFD)
Prefer fopen("re") over fopen("r")+fcntl(F_SETFD)

ok otto@ millert@


Revision tags: OPENBSD_5_6_BASE
# 1.37 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.36 17-Jan-2014 okan

ctype and other sign extension fixes.

with deraadt and millert, ok millert


Revision tags: OPENBSD_5_4_BASE
# 1.35 29-Apr-2013 okan

use FD_CLOEXEC instead of 1; from David Hill

ok otto


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.34 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 10-May-2004 deraadt

delint; millert ok


# 1.31 10-May-2004 millert

Get rid of the ancient "clobber" command. It was really only for debugging
purposes. Noticed and OK by deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.30 24-Oct-2003 avsm

dont compare int to NULL, millert@ ok


# 1.29 13-Oct-2003 tedu

better realloc. ok deraadt jose


Revision tags: OPENBSD_3_4_BASE
# 1.28 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.27 21-Nov-2001 millert

o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible


# 1.26 21-Nov-2001 millert

o ANSIfy
o Style nits
o Use const to silent stupid -Wall warnings
o strnc{py,at} -> strlc{py,at}
o Use strpbrk() instead of homegrown anyof()
o Use NULL instead of #defines with 0 cast to a pointer
This still could use a proper audit


# 1.25 20-Nov-2001 millert

Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.

This should make the flow of control a bit more grokable but the
code is still ugly.


# 1.24 17-Nov-2001 deraadt

properly bail out of incfile(); millert ok


Revision tags: OPENBSD_3_0_BASE
# 1.23 23-Jun-2001 millert

Remove evil #ifdef __GNUC__ garbage to avoid longjmp clobbering and
use volatile instead.


Revision tags: OPENBSD_2_9_BASE
# 1.22 16-Jan-2001 millert

Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long


Revision tags: OPENBSD_2_8_BASE
# 1.21 06-Jul-2000 deraadt

printf with % for the prompt


# 1.20 30-Jun-2000 millert

warnx?/errx? paranoia (use "%s" not a bare string unless it is a
constant). These are not security holes but it is worth fixing
them anyway both for robustness and so folks looking for examples
in the tree are not misled into doing something potentially dangerous.
Furthermore, it is a bad idea to assume that pathnames will not
include '%' in them and that error routines don't return strings
with '%' in them (especially in light of the possibility of locales).


Revision tags: OPENBSD_2_7_BASE
# 1.19 25-Apr-2000 millert

branches: 1.19.2;
When incorporating new messages, clear the "new" count before the
inc so the count of new messages is useful afterwards. This makes
mail behave more like the SunOS version in this respect.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.18 08-Sep-1998 millert

Fix comments in .mailrc where there is no space after the hash (#). Noted by pjanzen@foatdi.harvard.edu


# 1.17 12-Jun-1998 millert

back out some signal changes that can cause mail to hang when quitting due to SIGCHLD blockage


# 1.16 04-May-1998 millert

Never remove a mail spool, as we may not have proper prics, just truncate. Also block signals in a few critical areas


Revision tags: OPENBSD_2_3_BASE
# 1.15 14-Nov-1997 millert

NetBSD changes (mostly comsmetic):
replace panic() with calls to err()/errx()
use S_IS* instead of doing by hand with S_IF*.
Use TIMESPEC_TO_TIMEVAL() and gettimeofday instead of time(2)
Use _POSIX_VDISABLE, not 0
Kill register


Revision tags: OPENBSD_2_2_BASE
# 1.14 30-Jul-1997 millert

Make istrcpy() take a size (not length) field, now called istrncpy().
Change some strcpy() -> strncpy() out of paranoia.


# 1.13 30-Jul-1997 millert

Fix one possible oflow (not exploitable) and do a wee bit of KNF.
Much more remains to be done.


# 1.12 24-Jul-1997 millert

tempnam(3) goes bye bye.


# 1.11 24-Jul-1997 millert

Replace 3 tempnam()'s with mkstemp. The two left look tricky.


# 1.10 22-Jul-1997 millert

incfile() needs to lock the mail spool so it doesn't get partial messages.
Noticed by Theo.


# 1.9 22-Jul-1997 millert

Release signals when we get an error condition in incfile().


# 1.8 14-Jul-1997 millert

NOSTR -> NULL
Use sigsetjmp/siglongjmp instead of sigjmp/longjmp for portability.


# 1.7 13-Jul-1997 millert

bcopy() -> memcpy() and fix some casts.


# 1.6 13-Jul-1997 millert

Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety


# 1.5 30-May-1997 deraadt

overflows abound


Revision tags: OPENBSD_2_1_BASE
# 1.4 17-Jan-1997 millert

r?index -> strr?chr


Revision tags: OPENBSD_2_0_BASE
# 1.3 11-Jun-1996 deraadt

from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock.
- Fix PR/2247: Don't call unknown users "ubluit". Issue an error message.
- Fix/add prototypes.
- Fix warnings.
- Use POSIX signal mask calls.


# 1.2 27-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.42 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.41 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.40 16-Sep-2018 millert

Replace the local getname() and getuserid() functions with calls
to user_from_uid(3) and uid_from_user(3). This requires sprinkling
const in a few places to match the return value of user_from_uid(3).
OK tb@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.39 16-Oct-2015 mmcc

Modernize allocation by:

* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported

ok beck@, jung@, millert@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.38 26-Oct-2014 guenther

Prefer mkostemp(O_CLOEXEC) over mkstemp()+fcntl(F_SETFD)
Prefer fopen("re") over fopen("r")+fcntl(F_SETFD)

ok otto@ millert@


Revision tags: OPENBSD_5_6_BASE
# 1.37 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.36 17-Jan-2014 okan

ctype and other sign extension fixes.

with deraadt and millert, ok millert


Revision tags: OPENBSD_5_4_BASE
# 1.35 29-Apr-2013 okan

use FD_CLOEXEC instead of 1; from David Hill

ok otto


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.34 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 10-May-2004 deraadt

delint; millert ok


# 1.31 10-May-2004 millert

Get rid of the ancient "clobber" command. It was really only for debugging
purposes. Noticed and OK by deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.30 24-Oct-2003 avsm

dont compare int to NULL, millert@ ok


# 1.29 13-Oct-2003 tedu

better realloc. ok deraadt jose


Revision tags: OPENBSD_3_4_BASE
# 1.28 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.27 21-Nov-2001 millert

o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible


# 1.26 21-Nov-2001 millert

o ANSIfy
o Style nits
o Use const to silent stupid -Wall warnings
o strnc{py,at} -> strlc{py,at}
o Use strpbrk() instead of homegrown anyof()
o Use NULL instead of #defines with 0 cast to a pointer
This still could use a proper audit


# 1.25 20-Nov-2001 millert

Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.

This should make the flow of control a bit more grokable but the
code is still ugly.


# 1.24 17-Nov-2001 deraadt

properly bail out of incfile(); millert ok


Revision tags: OPENBSD_3_0_BASE
# 1.23 23-Jun-2001 millert

Remove evil #ifdef __GNUC__ garbage to avoid longjmp clobbering and
use volatile instead.


Revision tags: OPENBSD_2_9_BASE
# 1.22 16-Jan-2001 millert

Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long


Revision tags: OPENBSD_2_8_BASE
# 1.21 06-Jul-2000 deraadt

printf with % for the prompt


# 1.20 30-Jun-2000 millert

warnx?/errx? paranoia (use "%s" not a bare string unless it is a
constant). These are not security holes but it is worth fixing
them anyway both for robustness and so folks looking for examples
in the tree are not misled into doing something potentially dangerous.
Furthermore, it is a bad idea to assume that pathnames will not
include '%' in them and that error routines don't return strings
with '%' in them (especially in light of the possibility of locales).


Revision tags: OPENBSD_2_7_BASE
# 1.19 25-Apr-2000 millert

branches: 1.19.2;
When incorporating new messages, clear the "new" count before the
inc so the count of new messages is useful afterwards. This makes
mail behave more like the SunOS version in this respect.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.18 08-Sep-1998 millert

Fix comments in .mailrc where there is no space after the hash (#). Noted by pjanzen@foatdi.harvard.edu


# 1.17 12-Jun-1998 millert

back out some signal changes that can cause mail to hang when quitting due to SIGCHLD blockage


# 1.16 04-May-1998 millert

Never remove a mail spool, as we may not have proper prics, just truncate. Also block signals in a few critical areas


Revision tags: OPENBSD_2_3_BASE
# 1.15 14-Nov-1997 millert

NetBSD changes (mostly comsmetic):
replace panic() with calls to err()/errx()
use S_IS* instead of doing by hand with S_IF*.
Use TIMESPEC_TO_TIMEVAL() and gettimeofday instead of time(2)
Use _POSIX_VDISABLE, not 0
Kill register


Revision tags: OPENBSD_2_2_BASE
# 1.14 30-Jul-1997 millert

Make istrcpy() take a size (not length) field, now called istrncpy().
Change some strcpy() -> strncpy() out of paranoia.


# 1.13 30-Jul-1997 millert

Fix one possible oflow (not exploitable) and do a wee bit of KNF.
Much more remains to be done.


# 1.12 24-Jul-1997 millert

tempnam(3) goes bye bye.


# 1.11 24-Jul-1997 millert

Replace 3 tempnam()'s with mkstemp. The two left look tricky.


# 1.10 22-Jul-1997 millert

incfile() needs to lock the mail spool so it doesn't get partial messages.
Noticed by Theo.


# 1.9 22-Jul-1997 millert

Release signals when we get an error condition in incfile().


# 1.8 14-Jul-1997 millert

NOSTR -> NULL
Use sigsetjmp/siglongjmp instead of sigjmp/longjmp for portability.


# 1.7 13-Jul-1997 millert

bcopy() -> memcpy() and fix some casts.


# 1.6 13-Jul-1997 millert

Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety


# 1.5 30-May-1997 deraadt

overflows abound


Revision tags: OPENBSD_2_1_BASE
# 1.4 17-Jan-1997 millert

r?index -> strr?chr


Revision tags: OPENBSD_2_0_BASE
# 1.3 11-Jun-1996 deraadt

from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock.
- Fix PR/2247: Don't call unknown users "ubluit". Issue an error message.
- Fix/add prototypes.
- Fix warnings.
- Use POSIX signal mask calls.


# 1.2 27-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.41 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.40 16-Sep-2018 millert

Replace the local getname() and getuserid() functions with calls
to user_from_uid(3) and uid_from_user(3). This requires sprinkling
const in a few places to match the return value of user_from_uid(3).
OK tb@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.39 16-Oct-2015 mmcc

Modernize allocation by:

* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported

ok beck@, jung@, millert@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.38 26-Oct-2014 guenther

Prefer mkostemp(O_CLOEXEC) over mkstemp()+fcntl(F_SETFD)
Prefer fopen("re") over fopen("r")+fcntl(F_SETFD)

ok otto@ millert@


Revision tags: OPENBSD_5_6_BASE
# 1.37 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.36 17-Jan-2014 okan

ctype and other sign extension fixes.

with deraadt and millert, ok millert


Revision tags: OPENBSD_5_4_BASE
# 1.35 29-Apr-2013 okan

use FD_CLOEXEC instead of 1; from David Hill

ok otto


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.34 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 10-May-2004 deraadt

delint; millert ok


# 1.31 10-May-2004 millert

Get rid of the ancient "clobber" command. It was really only for debugging
purposes. Noticed and OK by deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.30 24-Oct-2003 avsm

dont compare int to NULL, millert@ ok


# 1.29 13-Oct-2003 tedu

better realloc. ok deraadt jose


Revision tags: OPENBSD_3_4_BASE
# 1.28 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.27 21-Nov-2001 millert

o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible


# 1.26 21-Nov-2001 millert

o ANSIfy
o Style nits
o Use const to silent stupid -Wall warnings
o strnc{py,at} -> strlc{py,at}
o Use strpbrk() instead of homegrown anyof()
o Use NULL instead of #defines with 0 cast to a pointer
This still could use a proper audit


# 1.25 20-Nov-2001 millert

Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.

This should make the flow of control a bit more grokable but the
code is still ugly.


# 1.24 17-Nov-2001 deraadt

properly bail out of incfile(); millert ok


Revision tags: OPENBSD_3_0_BASE
# 1.23 23-Jun-2001 millert

Remove evil #ifdef __GNUC__ garbage to avoid longjmp clobbering and
use volatile instead.


Revision tags: OPENBSD_2_9_BASE
# 1.22 16-Jan-2001 millert

Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long


Revision tags: OPENBSD_2_8_BASE
# 1.21 06-Jul-2000 deraadt

printf with % for the prompt


# 1.20 30-Jun-2000 millert

warnx?/errx? paranoia (use "%s" not a bare string unless it is a
constant). These are not security holes but it is worth fixing
them anyway both for robustness and so folks looking for examples
in the tree are not misled into doing something potentially dangerous.
Furthermore, it is a bad idea to assume that pathnames will not
include '%' in them and that error routines don't return strings
with '%' in them (especially in light of the possibility of locales).


Revision tags: OPENBSD_2_7_BASE
# 1.19 25-Apr-2000 millert

branches: 1.19.2;
When incorporating new messages, clear the "new" count before the
inc so the count of new messages is useful afterwards. This makes
mail behave more like the SunOS version in this respect.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.18 08-Sep-1998 millert

Fix comments in .mailrc where there is no space after the hash (#). Noted by pjanzen@foatdi.harvard.edu


# 1.17 12-Jun-1998 millert

back out some signal changes that can cause mail to hang when quitting due to SIGCHLD blockage


# 1.16 04-May-1998 millert

Never remove a mail spool, as we may not have proper prics, just truncate. Also block signals in a few critical areas


Revision tags: OPENBSD_2_3_BASE
# 1.15 14-Nov-1997 millert

NetBSD changes (mostly comsmetic):
replace panic() with calls to err()/errx()
use S_IS* instead of doing by hand with S_IF*.
Use TIMESPEC_TO_TIMEVAL() and gettimeofday instead of time(2)
Use _POSIX_VDISABLE, not 0
Kill register


Revision tags: OPENBSD_2_2_BASE
# 1.14 30-Jul-1997 millert

Make istrcpy() take a size (not length) field, now called istrncpy().
Change some strcpy() -> strncpy() out of paranoia.


# 1.13 30-Jul-1997 millert

Fix one possible oflow (not exploitable) and do a wee bit of KNF.
Much more remains to be done.


# 1.12 24-Jul-1997 millert

tempnam(3) goes bye bye.


# 1.11 24-Jul-1997 millert

Replace 3 tempnam()'s with mkstemp. The two left look tricky.


# 1.10 22-Jul-1997 millert

incfile() needs to lock the mail spool so it doesn't get partial messages.
Noticed by Theo.


# 1.9 22-Jul-1997 millert

Release signals when we get an error condition in incfile().


# 1.8 14-Jul-1997 millert

NOSTR -> NULL
Use sigsetjmp/siglongjmp instead of sigjmp/longjmp for portability.


# 1.7 13-Jul-1997 millert

bcopy() -> memcpy() and fix some casts.


# 1.6 13-Jul-1997 millert

Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety


# 1.5 30-May-1997 deraadt

overflows abound


Revision tags: OPENBSD_2_1_BASE
# 1.4 17-Jan-1997 millert

r?index -> strr?chr


Revision tags: OPENBSD_2_0_BASE
# 1.3 11-Jun-1996 deraadt

from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock.
- Fix PR/2247: Don't call unknown users "ubluit". Issue an error message.
- Fix/add prototypes.
- Fix warnings.
- Use POSIX signal mask calls.


# 1.2 27-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.40 16-Sep-2018 millert

Replace the local getname() and getuserid() functions with calls
to user_from_uid(3) and uid_from_user(3). This requires sprinkling
const in a few places to match the return value of user_from_uid(3).
OK tb@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.39 16-Oct-2015 mmcc

Modernize allocation by:

* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported

ok beck@, jung@, millert@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.38 26-Oct-2014 guenther

Prefer mkostemp(O_CLOEXEC) over mkstemp()+fcntl(F_SETFD)
Prefer fopen("re") over fopen("r")+fcntl(F_SETFD)

ok otto@ millert@


Revision tags: OPENBSD_5_6_BASE
# 1.37 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.36 17-Jan-2014 okan

ctype and other sign extension fixes.

with deraadt and millert, ok millert


Revision tags: OPENBSD_5_4_BASE
# 1.35 29-Apr-2013 okan

use FD_CLOEXEC instead of 1; from David Hill

ok otto


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.34 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 10-May-2004 deraadt

delint; millert ok


# 1.31 10-May-2004 millert

Get rid of the ancient "clobber" command. It was really only for debugging
purposes. Noticed and OK by deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.30 24-Oct-2003 avsm

dont compare int to NULL, millert@ ok


# 1.29 13-Oct-2003 tedu

better realloc. ok deraadt jose


Revision tags: OPENBSD_3_4_BASE
# 1.28 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.27 21-Nov-2001 millert

o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible


# 1.26 21-Nov-2001 millert

o ANSIfy
o Style nits
o Use const to silent stupid -Wall warnings
o strnc{py,at} -> strlc{py,at}
o Use strpbrk() instead of homegrown anyof()
o Use NULL instead of #defines with 0 cast to a pointer
This still could use a proper audit


# 1.25 20-Nov-2001 millert

Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.

This should make the flow of control a bit more grokable but the
code is still ugly.


# 1.24 17-Nov-2001 deraadt

properly bail out of incfile(); millert ok


Revision tags: OPENBSD_3_0_BASE
# 1.23 23-Jun-2001 millert

Remove evil #ifdef __GNUC__ garbage to avoid longjmp clobbering and
use volatile instead.


Revision tags: OPENBSD_2_9_BASE
# 1.22 16-Jan-2001 millert

Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long


Revision tags: OPENBSD_2_8_BASE
# 1.21 06-Jul-2000 deraadt

printf with % for the prompt


# 1.20 30-Jun-2000 millert

warnx?/errx? paranoia (use "%s" not a bare string unless it is a
constant). These are not security holes but it is worth fixing
them anyway both for robustness and so folks looking for examples
in the tree are not misled into doing something potentially dangerous.
Furthermore, it is a bad idea to assume that pathnames will not
include '%' in them and that error routines don't return strings
with '%' in them (especially in light of the possibility of locales).


Revision tags: OPENBSD_2_7_BASE
# 1.19 25-Apr-2000 millert

branches: 1.19.2;
When incorporating new messages, clear the "new" count before the
inc so the count of new messages is useful afterwards. This makes
mail behave more like the SunOS version in this respect.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.18 08-Sep-1998 millert

Fix comments in .mailrc where there is no space after the hash (#). Noted by pjanzen@foatdi.harvard.edu


# 1.17 12-Jun-1998 millert

back out some signal changes that can cause mail to hang when quitting due to SIGCHLD blockage


# 1.16 04-May-1998 millert

Never remove a mail spool, as we may not have proper prics, just truncate. Also block signals in a few critical areas


Revision tags: OPENBSD_2_3_BASE
# 1.15 14-Nov-1997 millert

NetBSD changes (mostly comsmetic):
replace panic() with calls to err()/errx()
use S_IS* instead of doing by hand with S_IF*.
Use TIMESPEC_TO_TIMEVAL() and gettimeofday instead of time(2)
Use _POSIX_VDISABLE, not 0
Kill register


Revision tags: OPENBSD_2_2_BASE
# 1.14 30-Jul-1997 millert

Make istrcpy() take a size (not length) field, now called istrncpy().
Change some strcpy() -> strncpy() out of paranoia.


# 1.13 30-Jul-1997 millert

Fix one possible oflow (not exploitable) and do a wee bit of KNF.
Much more remains to be done.


# 1.12 24-Jul-1997 millert

tempnam(3) goes bye bye.


# 1.11 24-Jul-1997 millert

Replace 3 tempnam()'s with mkstemp. The two left look tricky.


# 1.10 22-Jul-1997 millert

incfile() needs to lock the mail spool so it doesn't get partial messages.
Noticed by Theo.


# 1.9 22-Jul-1997 millert

Release signals when we get an error condition in incfile().


# 1.8 14-Jul-1997 millert

NOSTR -> NULL
Use sigsetjmp/siglongjmp instead of sigjmp/longjmp for portability.


# 1.7 13-Jul-1997 millert

bcopy() -> memcpy() and fix some casts.


# 1.6 13-Jul-1997 millert

Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety


# 1.5 30-May-1997 deraadt

overflows abound


Revision tags: OPENBSD_2_1_BASE
# 1.4 17-Jan-1997 millert

r?index -> strr?chr


Revision tags: OPENBSD_2_0_BASE
# 1.3 11-Jun-1996 deraadt

from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock.
- Fix PR/2247: Don't call unknown users "ubluit". Issue an error message.
- Fix/add prototypes.
- Fix warnings.
- Use POSIX signal mask calls.


# 1.2 27-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.39 16-Oct-2015 mmcc

Modernize allocation by:

* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported

ok beck@, jung@, millert@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.38 26-Oct-2014 guenther

Prefer mkostemp(O_CLOEXEC) over mkstemp()+fcntl(F_SETFD)
Prefer fopen("re") over fopen("r")+fcntl(F_SETFD)

ok otto@ millert@


Revision tags: OPENBSD_5_6_BASE
# 1.37 20-May-2014 guenther

Use errc/warnc to simplify code.
Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.36 17-Jan-2014 okan

ctype and other sign extension fixes.

with deraadt and millert, ok millert


Revision tags: OPENBSD_5_4_BASE
# 1.35 29-Apr-2013 okan

use FD_CLOEXEC instead of 1; from David Hill

ok otto


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.34 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.33 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.32 10-May-2004 deraadt

delint; millert ok


# 1.31 10-May-2004 millert

Get rid of the ancient "clobber" command. It was really only for debugging
purposes. Noticed and OK by deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.30 24-Oct-2003 avsm

dont compare int to NULL, millert@ ok


# 1.29 13-Oct-2003 tedu

better realloc. ok deraadt jose


Revision tags: OPENBSD_3_4_BASE
# 1.28 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.27 21-Nov-2001 millert

o kill strcpy()
o check return values of malloc and friends
o use strdup() when sensible


# 1.26 21-Nov-2001 millert

o ANSIfy
o Style nits
o Use const to silent stupid -Wall warnings
o strnc{py,at} -> strlc{py,at}
o Use strpbrk() instead of homegrown anyof()
o Use NULL instead of #defines with 0 cast to a pointer
This still could use a proper audit


# 1.25 20-Nov-2001 millert

Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.

This should make the flow of control a bit more grokable but the
code is still ugly.


# 1.24 17-Nov-2001 deraadt

properly bail out of incfile(); millert ok


Revision tags: OPENBSD_3_0_BASE
# 1.23 23-Jun-2001 millert

Remove evil #ifdef __GNUC__ garbage to avoid longjmp clobbering and
use volatile instead.


Revision tags: OPENBSD_2_9_BASE
# 1.22 16-Jan-2001 millert

Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long


Revision tags: OPENBSD_2_8_BASE
# 1.21 06-Jul-2000 deraadt

printf with % for the prompt


# 1.20 30-Jun-2000 millert

warnx?/errx? paranoia (use "%s" not a bare string unless it is a
constant). These are not security holes but it is worth fixing
them anyway both for robustness and so folks looking for examples
in the tree are not misled into doing something potentially dangerous.
Furthermore, it is a bad idea to assume that pathnames will not
include '%' in them and that error routines don't return strings
with '%' in them (especially in light of the possibility of locales).


Revision tags: OPENBSD_2_7_BASE
# 1.19 25-Apr-2000 millert

branches: 1.19.2;
When incorporating new messages, clear the "new" count before the
inc so the count of new messages is useful afterwards. This makes
mail behave more like the SunOS version in this respect.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.18 08-Sep-1998 millert

Fix comments in .mailrc where there is no space after the hash (#). Noted by pjanzen@foatdi.harvard.edu


# 1.17 12-Jun-1998 millert

back out some signal changes that can cause mail to hang when quitting due to SIGCHLD blockage


# 1.16 04-May-1998 millert

Never remove a mail spool, as we may not have proper prics, just truncate. Also block signals in a few critical areas


Revision tags: OPENBSD_2_3_BASE
# 1.15 14-Nov-1997 millert

NetBSD changes (mostly comsmetic):
replace panic() with calls to err()/errx()
use S_IS* instead of doing by hand with S_IF*.
Use TIMESPEC_TO_TIMEVAL() and gettimeofday instead of time(2)
Use _POSIX_VDISABLE, not 0
Kill register


Revision tags: OPENBSD_2_2_BASE
# 1.14 30-Jul-1997 millert

Make istrcpy() take a size (not length) field, now called istrncpy().
Change some strcpy() -> strncpy() out of paranoia.


# 1.13 30-Jul-1997 millert

Fix one possible oflow (not exploitable) and do a wee bit of KNF.
Much more remains to be done.


# 1.12 24-Jul-1997 millert

tempnam(3) goes bye bye.


# 1.11 24-Jul-1997 millert

Replace 3 tempnam()'s with mkstemp. The two left look tricky.


# 1.10 22-Jul-1997 millert

incfile() needs to lock the mail spool so it doesn't get partial messages.
Noticed by Theo.


# 1.9 22-Jul-1997 millert

Release signals when we get an error condition in incfile().


# 1.8 14-Jul-1997 millert

NOSTR -> NULL
Use sigsetjmp/siglongjmp instead of sigjmp/longjmp for portability.


# 1.7 13-Jul-1997 millert

bcopy() -> memcpy() and fix some casts.


# 1.6 13-Jul-1997 millert

Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety


# 1.5 30-May-1997 deraadt

overflows abound


Revision tags: OPENBSD_2_1_BASE
# 1.4 17-Jan-1997 millert

r?index -> strr?chr


Revision tags: OPENBSD_2_0_BASE
# 1.3 11-Jun-1996 deraadt

from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock.
- Fix PR/2247: Don't call unknown users "ubluit". Issue an error message.
- Fix/add prototypes.
- Fix warnings.
- Use POSIX signal mask calls.


# 1.2 27-Mar-1996 niklas

From NetBSD: merge of 960317


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision