-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify string handling (piecemeal) #1085
Conversation
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
There was a problem hiding this 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.
I haven't tested this.
Do you mean this? commit 5e0c907a5b72b1f8a506939182f283ed4c088dbb (HEAD -> str, gh/str)
Author: Alejandro Colomar <[email protected]>
Date: Wed Jul 3 23:49:04 2024 +0200
src/suauth.c: check_su_auth(): Use pointers to simplify
Signed-off-by: Alejandro Colomar <[email protected]>
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?
|
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 :) |
There was a problem hiding this 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.
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. |
This is a subset of the patches from #1048 for an easier review.
Cc: @hallyn
Cc: @ikerexxe