OpenBSD CVS

CVS log for src/lib/libutil/imsg-buffer.c


[BACK] Up to [local] / src / lib / libutil

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.18 / (download) - annotate - [select for diffs], Tue Dec 12 15:47:41 2023 UTC (5 months, 4 weeks ago) by claudio
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, HEAD
Changes since 1.17: +235 -20 lines
Diff to previous 1.17 (colored)

Extend imsg and ibuf API with useful getter methods

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@

Revision 1.17 / (download) - annotate - [select for diffs], Tue Oct 24 14:05:23 2023 UTC (7 months, 2 weeks ago) by claudio
Branch: MAIN
Changes since 1.16: +1 -10 lines
Diff to previous 1.16 (colored)

Require callers to use ibuf_fd_get() to extract the passed fd from an ibuf.

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@

Revision 1.16 / (download) - annotate - [select for diffs], Mon Jun 19 17:19:50 2023 UTC (11 months, 3 weeks ago) by claudio
Branch: MAIN
CVS Tags: OPENBSD_7_4_BASE, OPENBSD_7_4
Changes since 1.15: +187 -30 lines
Diff to previous 1.15 (colored)

Improve the ibuf API by adding these functions:
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@

Revision 1.15 / (download) - annotate - [select for diffs], Tue May 23 12:41:28 2023 UTC (12 months, 2 weeks ago) by claudio
Branch: MAIN
Changes since 1.14: +20 -7 lines
Diff to previous 1.14 (colored)

Avoid calling malloc with a zero length argument.

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@

Revision 1.14 / (download) - annotate - [select for diffs], Sat Apr 23 08:57:52 2022 UTC (2 years, 1 month ago) by tobias
Branch: MAIN
CVS Tags: OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2
Changes since 1.13: +14 -4 lines
Diff to previous 1.13 (colored)

Verify sizes before arithmetic operations

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

Revision 1.13 / (download) - annotate - [select for diffs], Wed Mar 31 17:42:24 2021 UTC (3 years, 2 months ago) by eric
Branch: MAIN
CVS Tags: OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9
Changes since 1.12: +10 -8 lines
Diff to previous 1.12 (colored)

change the barrier so that fd's are always passed and received with
the first byte of the imsg they belong to.

idea, tweaks and ok claudio@

Revision 1.12 / (download) - annotate - [select for diffs], Sun Jan 20 02:50:03 2019 UTC (5 years, 4 months ago) by bcook
Branch: MAIN
CVS Tags: OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7, OPENBSD_6_6_BASE, OPENBSD_6_6, OPENBSD_6_5_BASE, OPENBSD_6_5
Changes since 1.11: +2 -2 lines
Diff to previous 1.11 (colored)

Change imsg header definitions to use standard types.

ok deraadt@ claudio@

Revision 1.11 / (download) - annotate - [select for diffs], Thu Dec 14 09:27:44 2017 UTC (6 years, 5 months ago) by kettenis
Branch: MAIN
CVS Tags: OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3
Changes since 1.10: +7 -7 lines
Diff to previous 1.10 (colored)

Make a few internal symbols static and add a Symbols.map version script
to control which symbols are exported from the shared library.

ok guenther@, deraadt@, jca@

Revision 1.10 / (download) - annotate - [select for diffs], Tue Apr 11 09:57:19 2017 UTC (7 years, 2 months ago) by reyk
Branch: MAIN
CVS Tags: OPENBSD_6_2_BASE, OPENBSD_6_2
Changes since 1.9: +2 -2 lines
Diff to previous 1.9 (colored)

Use freezero(3) for the imsg framework in imsg_free(3) and ibuf_free(3).

In our privsep model, imsg is often used to transport sensitive
information between processes.  But a process might free an imsg, and
reuse the memory for a different thing.  iked uses some
explicit_bzero() to clean imsg-buffer but doing it in the library with
the freezero() is less error-prone and also benefits other daemons.

OK deraadt@ jsing@ claudio@

Revision 1.9 / (download) - annotate - [select for diffs], Fri Mar 17 14:51:26 2017 UTC (7 years, 2 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.8: +2 -2 lines
Diff to previous 1.8 (colored)

Grow buffers using recallocarray, to avoid the potential dribble that
the standard realloc*() functions can leave behind.  imsg buffers are
sometimes used in protocol stacks which require some secrecy, and layering
violations would be needed to resolve this issue otherwise.
Discussed with many.

Revision 1.8 / (download) - annotate - [select for diffs], Tue Dec 29 18:05:01 2015 UTC (8 years, 5 months ago) by benno
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0, OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.7: +3 -1 lines
Diff to previous 1.7 (colored)

check for NULL in ibuf_free().
ok and slight improvement, mmcco@
ok semarie@ and encouragement tedu@ krw@

Revision 1.7 / (download) - annotate - [select for diffs], Sun Jul 12 18:40:49 2015 UTC (8 years, 11 months ago) by nicm
Branch: MAIN
CVS Tags: OPENBSD_5_8_BASE, OPENBSD_5_8
Changes since 1.6: +5 -5 lines
Diff to previous 1.6 (colored)

Use memset instead of bzero for better portability.

ok gilles claudio doug

Revision 1.6 / (download) - annotate - [select for diffs], Fri Jul 3 14:50:14 2015 UTC (8 years, 11 months ago) by brynet
Branch: MAIN
Changes since 1.5: +2 -1 lines
Diff to previous 1.5 (colored)

bzero cmsgbuf before using it, silences valgrind warnings.

henning@ "sure"

Revision 1.5 / (download) - annotate - [select for diffs], Thu Dec 25 22:20:52 2014 UTC (9 years, 5 months ago) by benno
Branch: MAIN
CVS Tags: OPENBSD_5_7_BASE, OPENBSD_5_7
Changes since 1.4: +2 -2 lines
Diff to previous 1.4 (colored)

return ERANGE instead of ENOMEM, so callers can differentiate real oom
from this case where we have a static buffer and cant realloc.

ok phessler, claudio, reyk

Revision 1.4 / (download) - annotate - [select for diffs], Mon Jun 30 00:25:17 2014 UTC (9 years, 11 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_5_6_BASE, OPENBSD_5_6
Changes since 1.3: +3 -2 lines
Diff to previous 1.3 (colored)

limits.h rather than sys/param.h

Revision 1.3 / (download) - annotate - [select for diffs], Wed Nov 13 20:40:24 2013 UTC (10 years, 6 months ago) by benno
Branch: MAIN
CVS Tags: OPENBSD_5_5_BASE, OPENBSD_5_5
Changes since 1.2: +3 -3 lines
Diff to previous 1.2 (colored)

original bug diagnosed by sthen: automatic retry in msgbuf_write on
EAGAIN causes spinning.

fix from claudio:
"Let msgbuf_write return -1 with errno EAGAIN. The users then must
check if this was the case and readd the event or poll again.  The
current handling in the imsg code is wrong for sure."

ok gilles

Revision 1.2 / (download) - annotate - [select for diffs], Sat Jun 2 21:46:53 2012 UTC (12 years ago) by gilles
Branch: MAIN
CVS Tags: OPENBSD_5_4_BASE, OPENBSD_5_4, OPENBSD_5_3_BASE, OPENBSD_5_3, OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.1: +17 -15 lines
Diff to previous 1.1 (colored)

in imsg_read() avoid calling recvmsg() if we detect that we will be short
on descriptors, this can be achieved thanks to the new getdtablecount()
system call. application may provide a reserve count to ensure that the
recvmsg() call is not called when they don't have enough descriptors to
work properly.

change the API so that transient errors that can be retried immediately
are retried within the function right away, whereas transient errors for
which the application may want to take action will set errno to EAGAIN.

ok deraadt@ and henning@

Revision 1.1 / (download) - annotate - [select for diffs], Wed May 26 16:44:32 2010 UTC (14 years ago) by nicm
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1, OPENBSD_5_0_BASE, OPENBSD_5_0, OPENBSD_4_9_BASE, OPENBSD_4_9, OPENBSD_4_8_BASE, OPENBSD_4_8

Move imsg into libutil and add a man page.

Minor bump for libutil.

Previous versions of this diff and man page looked at by various people.

"you should just commit" deraadt

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.