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
Unknown Object (File)
Fri, May 10, 7:05 PM
Unknown Object (File)
Sat, Apr 20, 11:32 PM
Unknown Object (File)
Sat, Apr 20, 5:56 AM
Unknown Object (File)
Mar 16 2024, 11:02 PM
Unknown Object (File)
Dec 20 2023, 4:50 AM
Unknown Object (File)
Aug 26 2023, 2:24 PM
Unknown Object (File)
Aug 4 2023, 7:25 PM
Unknown Object (File)
Aug 4 2023, 7:23 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.