summaryrefslogtreecommitdiff
path: root/lib/libutil
AgeCommit message (Collapse)Author
2024-09-20remove unneeded semicolons; checked by millert@Jonathan Gray
2024-08-26Replace recallocarray() with a realloc() + memset() combo.Claudio Jeker
recallocarray(), with its guarantee that memory becoming unallocated is explicitly discarded, is too slow. In rpki-client forming one particular ibuf takes more then 4mins because every recallocarray() call ends up doing a fresh malloc + memcpy + freezero call. For sensitive data use ibuf_open() instead of ibuf_dynamic() to avoid any memory reallocations. OK tb@
2023-12-29Cleanup required headers form imsg.h.Claudio Jeker
Right now only sys/queue.h is required to be included for imsg.h. The only exception is if imsg_composev() is used, then sys/uio.h is needed to access struct iovec. OK tb@
2023-12-13filedescriptor -> file descriptorJonathan Gray
2023-12-12Move ibuf API from imsg_init.3 to ibuf_add.3Claudio Jeker
Document all new functions added and adjust examples in imsg_init.3 to follow the new way of handling messages. OK tb@
2023-12-12Extend imsg and ibuf API with useful getter methodsClaudio Jeker
For ibufs: - various getters for ibufs (ibuf_get* and ibuf_skip) - additional ibuf set/add functions that don't alter byte order - ibuf_truncate and ibuf_rewind - ibuf_from_buffer and ibuf_from_ibuf to populate a reader ibuf - a getter for the msgbuf queuelen For imsg: - various getters for imsg (especially imsg_get_data() which can be used in most cases as a simple one call api with all error checks). All the imsg.hdr fields can also be accessed by getters. - The imsg data is now actually an ibuf but the old imsg.data pointer is kept for now to not break every imsg application. - Introduce imsg_forward to simply forward a message from one channel to an other (used in the control socket code). Since this requires a major bump take the oportunity to also cleanup some function signatures to use size_t for length fields. Also internal data structures are removed from the public header. With and OK tb@
2023-11-18Rename internal function imsg_get_fd() to imsg_dequeue_fd().Claudio Jeker
OK tb@
2023-11-17The term peerid originated from bgpd. It is time to generalize this andClaudio Jeker
just call it id. This only targets the function arguments but not the struct imsg_hdr field since that is a major API break. OK tb@
2023-11-17rename struct imsgbuf *ibuf to *imsgbuf since ibuf is too close toClaudio Jeker
struct ibuf and just causes confusion for little gain. OK tb@ stsp@
2023-11-10Give ober_printf_elements() a ber_element array, similar toMartijn van Duren
ober_scanf_elements(). This allows us to move down and back up multiple levels in with nested sequences and sets. While here, on failure, make sure we free (and unlink if needed) all elements we created. OK claudio@, tb@
2023-10-24Require callers to use ibuf_fd_get() to extract the passed fd from an ibuf.Claudio Jeker
In imsg_free() close any fd that was not claimed automatically to prevent filedescriptor leaks. In ibuf_dequeue() remvoe code which is now part of imsg_free(). OK tb@
2023-09-28add a missing .Fa macroIngo Schwarze
2023-09-28fix two wrong function names in the description;Ingo Schwarze
from <Lucas at sexy dot is>
2023-08-22Don't fail in ober_scanf_elements() when encountering empty sequences.Gerhard Roth
Ok martijn@
2023-06-20responsibilty -> responsibilityJonathan Gray
2023-06-20- filedescriptor -> file descriptor, as per the rest of the pageJason McIntyre
- missing full stop
2023-06-19Improve the ibuf API by adding these functions:Claudio Jeker
Functions extending ibuf_add to work with more specific data types ibuf_add_buf, ibuf_add_zero, ibuf_add_n8, ibuf_add_n16, ibuf_add_n32, ibuf_add_n64 Functions replacing ibuf_seek where data at a specific offset is modified ibuf_set, ibuf_set_n8, ibuf_set_n16, ibuf_set_n32, ibuf_set_n64 Functions to check, get and set the filedescriptor stored on the ibuf ibuf_fd_avail, ibuf_fd_get, ibuf_fd_set and ibuf_data() to access the data buffer, to be used together with ibuf_size() On top of this add an optimized imsg_compose_ibuf() where an ibuf is wrapped into an imsg in an efficent way. Finally remove msgbuf_drain since it is not used by anything outside of the ibuf code. Because of this removal bump the major of libutil. Remove ibuf_data() in iked since the same function is now provided by libutil. OK tb@
2023-05-23Avoid calling malloc with a zero length argument.Claudio Jeker
ibuf_open() will return an error in this case while ibuf_dynamic() accepts a 0 len argument and just initialized the buffer and length to zero. A later ibuf_realloc() call will take care of allocating the buffer. Additionally switch from malloc() to calloc() when allocating the buffer this way the buffer is initalized and in ibuf_reserve() an addtional memset() is used to make sure that the reserved data is zeroed. OK tb@
2023-03-08Delete obsolete /* ARGSUSED */ lint comments.Philip Guenther
ok miod@ millert@
2023-01-04Christos Zoulas agreed to rescind clause 3 and 4 inJonathan Gray
NetBSD fsck.8 rev 1.35 fsutil.h rev 1.14 pathnames.h rev 1.2 netgroup_mkdb.8 rev 1.9 netgroup_mkdb.c rev 1.18 str.c rev 1.7 str.h rev 1.4 rdate.8 rev 1.11 rdate.c rev 1.19 extern.h rev 1.14 getnetgrent.c rev 1.41 netgroup.h rev 1.10 fparseln.3 rev 1.4 fparseln.c rev 1.10 our stringlist.c/stringlist.h are derived from getnetgrent.c rfc868time.c from rdate.c newfs/pathnames.h from fsck/pathnames.h https://mail-index.netbsd.org/source-changes/2009/10/21/msg002182.html Not all files are covered as some had copyright assigned to TNF in 1998.
2022-12-27spelling fixes; from paul tagliamonteJason McIntyre
any changes not taken noted on tech, but chiefly here i did not take the cancelation - cancellation changes;
2022-11-03When decoding a sequence/set, make sure that:Martijn van Duren
- We don't create an uninitialized element when there are no subelements to decode - If subelements overflow we return EINVAL While here fix an eyesore of a line continuation. OK claudio@
2022-08-26Backout "Only return file descriptors to block or character devices"Klemens Nanni
mount_mfs(8) no monger mounts "/build" with the following fstab(5) entry: /dev/sd0b /build mfs rw,noperm,nodev,nosuid,-s=2064348,noauto as found out by bluhm the hard way.
2022-08-25Only return file descriptors to block or character devicesKlemens Nanni
If the requested path contained a slash, opendev(3) blindly opened the file and returned a file descriptor to it. Check for block or character devices (according to OPENDEV_BLCK) and fail for other types. Spotted through installboot(8) which happily opened a stage file as device when forgetting the device argument: # installboot -v ./biosboot Using / as root installing bootstrap on ./biosboot using first-stage /usr/mdec/biosboot, second-stage /usr/mdec/boot installboot: disklabel: ./biosboot: Inappropriate ioctl for device This makes it fail earlier, as expected: # installboot -v ./biosboot installboot: open: ./biosboot: Block device required The case where opendev(3) is passed a string not containing a slash, i.e. a supposed DUID, is fine, as diskmap(4) will ensure that only valid device paths are returned, if the DUID is valid. Feedback OK millert
2022-05-19Document that imsg_add(3) frees its msg argument on failure.Stefan Sperling
ok op@ claudio@
2022-05-11Mark pw_error as __dead in prototype to match the function definition.Todd C. Miller
From Matthew Martin.
2022-04-23Verify sizes before arithmetic operationsTobias Stoeckmann
Unsigned overflows are not a bug in C but we have to make sure that requested buffer sizes will be actually available. If not, set errno to ERANGE and return an error value. ok deraadt, millert
2022-04-20Use glob to expand wildcards in "other device" paths rather than aJoshua Stein
custom implementation that only allowed matching all files in a directory. ok millert
2022-04-20Make the termp and winp arguments for openpty, et al. const.Todd C. Miller
This matches the prototypes in glibc and musl libc. From Matthew Martin. OK tb@
2022-03-31man pages: add missing commas between subordinate and main clausesChristian Weisgerber
jmc@ dislikes a comma before "then" in a conditional, so leave those untouched. ok jmc@
2022-03-11Revert previous commit. The problem it was attempting to fix was alreadyDarren Tucker
fixed by tb@ in rev 1.20. Spotted by tb@
2022-03-11Check for underflow as well as overflow when scaling negative numbers.Darren Tucker
ok millert@
2022-02-18Avoid gendered language in man pages when not referring to a specificJonathan Gray
person. Rewrite or use singular they. ok thfr@ sthen@ daniel@ ian@ job@ kmos@ jcs@ ratchov@ phessler@ and others I'm likely missing on an earlier version. feedback tj@, feedback and ok jmc@
2022-01-28Only memcpy() into imsg->data if datalen is not 0. Passing a NULL pointerClaudio Jeker
to memcpy() is UB no matter if len is 0. Reported by fouzhe on openbgpd-portable github page. OK tb@
2021-10-31bump major after struct size changeTheo Buehler
2021-10-31Bump BER_MAX_OID_LEN to 128Theo Buehler
From martijn, discussed with claudio, ok sthen
2021-10-24For open/openat, if the flags parameter does not contain O_CREAT, theTheo de Raadt
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
2021-10-21Sync ober_oid_cmp with ax_oid_cmp from libagentx.Martijn van Duren
This flips the returned signedness and adds the weight of 2 for parent-child relationship in both direction. This makes ober_oid_cmp consistent with the rest of the *_cmp based functions. OK tb@
2021-08-29fix an obvious mixup regarding the order of lines in the SYNOPSIS,Ingo Schwarze
and an omission below HISTORY
2021-08-29Add ober_dup. Needed for upcoming SNMPv3 support for trap receiver inMartijn van Duren
snmpd(8). OK jmatthew@ OK deraadt@ for bumping libutil now.
2021-06-20scan_scaled: fix rescaling for negative numbersTheo Buehler
As found by djm by fuzzing ssh, scan_scaled can overflow for negative numbers when rescaling is needed. This is because the rescaled fractional part is added without taking the sign into account. ok ian jca
2021-03-31tweak column widths of a .Bl -column tableIngo Schwarze
and avoid an over-long source line while here; OK martijn@ jmc@
2021-03-31change the barrier so that fd's are always passed and received withEric Faurot
the first byte of the imsg they belong to. idea, tweaks and ok claudio@
2021-03-12fix previousJonathan Gray
2021-03-12spellingJonathan Gray
2021-03-05Stop abusing display blocks under the authors section in order toanton
respect literal line breaks. This has the unwanted side effect of rendering the authors section using a monospace font over at man.openbsd.org. Instead use br macros to force line breaks. With help from and ok jmc@
2021-03-03s/byte/characterMartijn van Duren
Discussed with claudio@ Feedback jmc@
2021-02-22Make the ober_get_* set of function to accept a NULL-pointer.Martijn van Duren
This allows us to do ber-type checking inside ober_scanf_elements, which will allow for stricter ASN.1 parsing in the future. Manpage feedback and OK claudio@, jmc@ OK claudio@
2021-01-28Add '$' to ober_scanf_elements().Martijn van Duren
This allows us to enforce end of sequence/set without having to manually check be_next for NULL. No lib bump needed according to millert@ OK millert@ rob@
2021-01-22Gracefully handle any erroneous closing bracket/brace trailers inrob
ober_scanf_elements(). OK martijn@