Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

This is a subset of the patches from #1048 for an easier review.

Cc: @hallyn
Cc: @ikerexxe

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar alejandro-colomar changed the title Simplify string handling (redux) Simplify string handling (piecemeal) Oct 3, 2024
Copy link
Collaborator

@ikerexxe ikerexxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test the changes in the last commit? The change raises concerns about its potential to work correctly.

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Oct 11, 2024

Did you test the changes in the last commit?

I haven't tested this.

The change raises concerns about its potential to work correctly.

Do you mean this?

commit 5e0c907a5b72b1f8a506939182f283ed4c088dbb (HEAD -> str, gh/str)
Author: Alejandro Colomar <alx@kernel.org>
Date:   Wed Jul 3 23:49:04 2024 +0200

    src/suauth.c: check_su_auth(): Use pointers to simplify
    
    Signed-off-by: Alejandro Colomar <alx@kernel.org>

diff --git a/src/suauth.c b/src/suauth.c
index 895f1278..cbb33dc8 100644
--- a/src/suauth.c
+++ b/src/suauth.c
@@ -18,6 +18,7 @@
 
 #include "defines.h"
 #include "prototypes.h"
+#include "string/strchr/stpspn.h"
 #include "string/strchr/strrspn.h"
 #include "string/strtok/stpsep.h"
 
@@ -47,7 +48,6 @@ int check_su_auth (const char *actual_id,
                    const char *wanted_id,
                    bool su_to_root)
 {
-       int posn;
        const char field[] = ":";
        FILE *authfile_fd;
        char temp[1024];
@@ -73,6 +73,8 @@ int check_su_auth (const char *actual_id,
        }
 
        while (fgets (temp, sizeof (temp), authfile_fd) != NULL) {
+               char  *p;
+
                lines++;
 
                if (stpsep(temp, "\n") == NULL) {
@@ -84,12 +86,11 @@ int check_su_auth (const char *actual_id,
 
                stpcpy(strrspn(temp, " \t"), "");
 
-               posn = strspn(temp, " \t");
-
-               if (temp[posn] == '#' || temp[posn] == '\0') {
+               p = stpspn(temp, " \t");
+               if (*p == '#' || *p == '\0')
                        continue;
-               }
-               if (!(to_users = strtok (temp + posn, field))
+
+               if (!(to_users = strtok(p, field))
                    || !(from_users = strtok (NULL, field))
                    || !(action = strtok (NULL, field))
                    || strtok (NULL, field)) {

What do you think might be incorrect?

stpcpn() is defined as s_ + strspn(s_, accept);
so p = stpspn(temp, ...) would be equivalent to p = temp + strspn(temp, ...)
so *p would be equivalent to *(temp + posn), so equivalent to temp[posn].

@hallyn
Copy link
Member

hallyn commented Oct 13, 2024

Let me take a closer look at this tonight. I'm pretty sure I already reviewed it as part of 1048 but I'll make sure :)

Copy link
Member

@hallyn hallyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Only possible issue would still be replacing isspace() with only checking for ' ' and '\t', but the other chars like \f aren't really valid anyway, i believe.

@hallyn hallyn merged commit 4a15739 into shadow-maint:master Oct 14, 2024
@alejandro-colomar alejandro-colomar deleted the str branch October 14, 2024 10:23
@ikerexxe
Copy link
Collaborator

Do you mean this?

commit 5e0c907a5b72b1f8a506939182f283ed4c088dbb (HEAD -> str, gh/str)

Yes, I meant that one, and there's nothing I can point to that might fail. It was just a feeling more than anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants