Bug 252551

Summary: POSIX compliance: writev does not return EINVAL when iovcnt == 0
Product: Base System Reporter: Alan Somers <asomers>
Component: kernAssignee: Alan Somers <asomers>
Status: Closed Not A Bug    
Severity: Affects Many People CC: kevans
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
return EINVAL from writev and friends if iovcnt = 0 none

Description Alan Somers freebsd_committer freebsd_triage 2021-01-10 04:28:56 UTC
POSIX requires that readv and writev return EINVAL when iovcnt == 0.  Our own man pages document that condition as well.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html

However, we accept iovcnt == 0, do nothing, and return 0.  That's not inherently unreasonable, but it's not POSIX-compliant.  From inspection, OpenBSD and NetBSD do not have this bug, but DragonflyBSD does.
Comment 1 Alan Somers freebsd_committer freebsd_triage 2021-01-10 04:45:03 UTC
Created attachment 221435 [details]
return EINVAL from writev and friends if iovcnt = 0
Comment 2 Alan Somers freebsd_committer freebsd_triage 2021-01-10 04:50:57 UTC
Actually, on closer inspection POSIX says that writev "may fail", not "shall fail" if iovcnt is out of bounds.  So I guess this isn't a bug after all.