Page MenuHomeFreeBSD

Fix one more place uio_resid is truncated to int
ClosedPublic

Authored by cem on Jun 26 2017, 8:56 PM.
Tags
None
Referenced Files
F107184873: D11373.diff
Sat, Jan 11, 9:09 AM
Unknown Object (File)
Fri, Jan 3, 9:10 PM
Unknown Object (File)
Fri, Jan 3, 12:29 PM
Unknown Object (File)
Nov 27 2024, 7:50 PM
Unknown Object (File)
Nov 5 2024, 11:09 AM
Unknown Object (File)
Oct 2 2024, 1:17 PM
Unknown Object (File)
Sep 23 2024, 8:08 AM
Unknown Object (File)
Sep 21 2024, 9:31 PM
Subscribers

Details

Summary

A follow-up to r231949 and r194990.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

This is fine in principle, but qmin() is the wrong function to use. uio_resid is not of quad_t type. Use normal comparision operations there.

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

Hm, the rest of this function assumes that "total" fits in an int.

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

It will fit indeed, because len is int. Just that the comparision should use unclipped value of uio_resid.

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

quad_t encompasses all values ssize_t can have, on current platforms. It's too bad we don't have type-safe min/max macros like Linux.

By normal comparison operations, you mean trinary operator?

ngie added inline comments.
sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

So... uqmin...?

sys/sys/libkern.h:static __inline u_quad_t uqmin(u_quad_t a, u_quad_t b) { return (a < b ? a : b); }

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

Actually, szmin?

static __inline ssize_t szmin(ssize_t a, ssize_t b) { return (a < b ? a : b); }

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30109)

It does not matter what quad_t current domain is.

I mean, use normal C comparision operators like <, be it used in ?: or if is not important. Normal integer promotion rules make it correct.

Replace qmin() with expanded form of min.

This revision is now accepted and ready to land.Jun 27 2017, 5:08 PM
ngie added inline comments.
sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30136)

Could you please add a comment so someone doesn't reintroduce the bug after they note that the expression is similar to min(..)?

kib added inline comments.
sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30136)

Style states that () should be not used, since they are not needed.

sys/kern/uipc_mbuf.c
1520 ↗(On Diff #30136)

It also makes an allowance for confusion.

This revision was automatically updated to reflect the committed changes.