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)
Sun, Oct 5, 10:16 PM
Unknown Object (File)
Thu, Sep 25, 9:39 PM
Unknown Object (File)
Aug 25 2025, 1:01 PM
Unknown Object (File)
Aug 4 2025, 12:25 AM
Unknown Object (File)
Jul 31 2025, 2:09 PM
Unknown Object (File)
Jul 20 2025, 10:49 AM
Unknown Object (File)
Jul 19 2025, 2:15 PM
Unknown Object (File)
Jul 18 2025, 10:50 AM
Subscribers

Details

Summary

A follow-up to r231949 and r194990.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 10151
Build 10574: arc lint + arc unit

Event Timeline

sys/kern/uipc_mbuf.c
1520

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

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

sys/kern/uipc_mbuf.c
1520

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

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

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

Actually, szmin?

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

sys/kern/uipc_mbuf.c
1520

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

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

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

sys/kern/uipc_mbuf.c
1520

It also makes an allowance for confusion.

This revision was automatically updated to reflect the committed changes.