Page MenuHomeFreeBSD

Unbreak nscd(8).
ClosedPublic

Authored by trasz on Oct 6 2018, 6:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 7 2024, 10:23 PM
Unknown Object (File)
Jan 4 2024, 9:29 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Unknown Object (File)
Jan 4 2024, 9:26 PM
Subscribers

Details

Summary

Unbreak nscd(8). Without this change the CMSG gets truncated.
No idea how it worked before.

It also splits checks into separate "ifs", with a small tweak to debug.h
it makes it easier to see which one fails.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 20555
Build 19977: arc lint + arc unit

Event Timeline

trasz added a subscriber: des.
This revision is now accepted and ready to land.Oct 7 2018, 12:33 PM
des requested changes to this revision.Oct 9 2018, 9:16 AM

The answer to “how it worked before” is that it didn't. It has never worked properly.

usr.sbin/nscd/query.c
192–204

Please don't do this. Just fix the style issues in the original. I might even go one further and merge the four consistency checks with the recvmsg() call since they have the exact same error handling code. The fact that they're not really exactly the same because the macro uses __LINE__ is a bug, not a feature.

This revision now requires changes to proceed.Oct 9 2018, 9:16 AM
trasz marked an inline comment as done.Oct 9 2018, 2:28 PM
trasz added inline comments.
usr.sbin/nscd/query.c
192–204

As it is now, it's useless. However, with one small diff (to be committed separately), it actually starts being kind of useful:

--- debug.c     (revision 339219)
+++ debug.c     (working copy)                                      
@@ -131,7 +131,7 @@
                for (i = 0; i < trace_level; ++i)
                        printf("\t");
                                                      
-               printf("<= %s\n", s);                   
+               printf("<= %s, %s: %d\n", s, f, l);
        }     
 }

Having said that, the part in question doesn't belong here. So, I'll redo the diff.

trasz edited the summary of this revision. (Show Details)

Remove unrelated parts of the diff, as suggested by des@.

des requested changes to this revision.Oct 30 2018, 12:31 PM

I believe this is correct (with or without the suggested changes), but send_credentials() in usr.sbin/nscd/nscdcli.c also needs to be fixed. It was not touched by rS158257, which introduced the bug you are fixing here while trying to fix another, so the bug is slightly different. It is supposed to be (almost) identical to lib/libc/net/nscachedcli.c; the latter is actually the former ported into libc.

Both files as well as usr.sbin/nscd/query.c have pervasive style issues, as I pointed out when nscd was first imported, but perhaps it's best to leave that for later.

usr.sbin/nscd/query.c
175

This is technically correct, but I'd still rather spell it out explicitly with CMSG_SPACE (not CMSG_LEN).

186–187

We should probably check cred_hdr.msg_controllen here.

This revision now requires changes to proceed.Oct 30 2018, 12:31 PM
trasz marked an inline comment as done.

One more length check.

des requested changes to this revision.Nov 1 2018, 8:15 AM

This version has a couple of regressions from the previous one. Remember that CMSG_SPACE and CMSG_LEN already include space for the header, plus alignment and padding. See CMSG_DATA(3) and sys/sys/socket.h.

usr.sbin/nscd/nscdcli.c
148

struct cmsgcred

156

struct cmsgcred

usr.sbin/nscd/query.c
175

struct cmsgcred

This revision now requires changes to proceed.Nov 1 2018, 8:15 AM
trasz marked 3 inline comments as done.Nov 1 2018, 1:14 PM
This revision is now accepted and ready to land.Nov 1 2018, 2:11 PM
This revision was automatically updated to reflect the committed changes.