Skip to content
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

Add strprefix(), and use it instead of its pattern #1152

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Dec 10, 2024


Revisions:

v1b
  • Rebase
$ git range-diff gh/streq..gh/sp streq..sp 
 1:  e07e64d0 =  1:  9a35d316 lib/, src/: Reduce scope of local variables
 2:  8adca7da =  2:  b93dff45 lib/string/strcmp/: strprefix(): Add API
 3:  8f40e0a8 =  3:  2276c5f3 lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern
 4:  8bb3d486 =  4:  da55cf18 lib/, src/: Use strprefix() instead of its pattern
 5:  931e5e1c =  5:  cce5feac lib/env.c: sanitize_env(): Use !strprefix() instead of its pattern
 6:  b02ba83c !  6:  19b7f8fd lib/: Use strprefix() instead of its pattern
    @@ src/login_nopam.c
      
     @@ src/login_nopam.c: static const char *resolve_hostname (const char *string)
      
    - static bool from_match (const char *tok, const char *string)
    + static bool from_match (char *tok, const char *string)
      {
     -  size_t tok_len;
     -
        /*
         * If a token has the magic value "ALL" the match always succeeds. Return
         * true if the token fully matches the string. If the token is a domain
    -@@ src/login_nopam.c: static bool from_match (const char *tok, const char *string)
    +@@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
        if (string_match (tok, string)) {       /* ALL or exact match */
                return true;
        } else if (tok[0] == '.') {     /* domain: match last fields */
    @@ src/login_nopam.c: static bool from_match (const char *tok, const char *string)
                str_len = strlen (string);
                tok_len = strlen (tok);
                if (   (str_len > tok_len)
    -@@ src/login_nopam.c: static bool from_match (const char *tok, const char *string)
    +@@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
                if (strchr (string, '.') == NULL) {
                        return true;
                }
 7:  1e7bee82 =  7:  e80e4426 lib/: Use !strprefix() instead of its pattern
 8:  0b8ffbaf =  8:  01a6a676 src/check_subid_range.c: main(): Remove local variable
 9:  309cc8f7 !  9:  241144c7 lib/, src/: Use strprefix() instead of its pattern
    @@ src/login_nopam.c: login_access(const char *user, const char *from)
      }
      
      /* list_match - match an item against a list of tokens with exceptions */
    -@@ src/login_nopam.c: static bool user_match (const char *tok, const char *string)
    +@@ src/login_nopam.c: static bool user_match (char *tok, const char *string)
        if (host != NULL) {
                return user_match(tok, string) && from_match(host, myhostname());
      #if HAVE_INNETGR
    @@ src/login_nopam.c: static bool user_match (const char *tok, const char *string)
                return (netgroup_match (tok + 1, NULL, string));
      #endif
        } else if (string_match (tok, string)) {        /* ALL or exact match */
    -@@ src/login_nopam.c: static bool from_match (const char *tok, const char *string)
    +@@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
         * if it matches the head of the string.
         */
      #if HAVE_INNETGR
v1c
  • Rebase
$ git range-diff gh/streq..gh/sp streq..sp 
 1:  9a35d316 =  1:  35bfc827 lib/, src/: Reduce scope of local variables
 2:  b93dff45 =  2:  d0a4432a lib/string/strcmp/: strprefix(): Add API
 3:  2276c5f3 =  3:  77dd8ab9 lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern
 4:  da55cf18 =  4:  f910e231 lib/, src/: Use strprefix() instead of its pattern
 5:  cce5feac =  5:  26492ce2 lib/env.c: sanitize_env(): Use !strprefix() instead of its pattern
 6:  19b7f8fd =  6:  aeca0e16 lib/: Use strprefix() instead of its pattern
 7:  e80e4426 =  7:  ceb708fe lib/: Use !strprefix() instead of its pattern
 8:  01a6a676 =  8:  cab07b7c src/check_subid_range.c: main(): Remove local variable
 9:  241144c7 =  9:  f9cdbc0e lib/, src/: Use strprefix() instead of its pattern
v1d
  • Rebase
$ git range-diff gh/streq..gh/sp streq..sp 
 1:  35bfc827 =  1:  1b0f6852 lib/, src/: Reduce scope of local variables
 2:  d0a4432a =  2:  ad0e1402 lib/string/strcmp/: strprefix(): Add API
 3:  77dd8ab9 !  3:  12e115e9 lib/, src/: Use s=strprefix(s,p)?:s instead of its pattern
    @@ src/newgrp.c
     +#include "string/strcmp/strprefix.h"
      #include "string/strdup/xstrdup.h"
      
    - 
    + #include <assert.h>
     @@ src/newgrp.c: static void syslog_sg (const char *name, const char *group)
        }
        if (tty == NULL) {
 4:  f910e231 =  4:  bef01549 lib/, src/: Use strprefix() instead of its pattern
 5:  26492ce2 =  5:  e8605ba1 lib/env.c: sanitize_env(): Use !strprefix() instead of its pattern
 6:  aeca0e16 =  6:  f93c7a74 lib/: Use strprefix() instead of its pattern
 7:  ceb708fe =  7:  58491ab4 lib/: Use !strprefix() instead of its pattern
 8:  cab07b7c =  8:  b12fa228 src/check_subid_range.c: main(): Remove local variable
 9:  f9cdbc0e !  9:  50537ddc lib/, src/: Use strprefix() instead of its pattern
    @@ src/grpck.c
      
      #ifdef SHADOWGRP
      #include "sgroupio.h"
    -@@ src/grpck.c: static void check_grp_file (int *errors, bool *changed)
    +@@ src/grpck.c: static void check_grp_file (bool *errors, bool *changed)
                 * Skip all NIS entries.
                 */
      
    @@ src/pwck.c
      #ifdef WITH_TCB
      #include "tcbfuncs.h"
      #endif                            /* WITH_TCB */
    -@@ src/pwck.c: static void check_pw_file (int *errors, bool *changed)
    +@@ src/pwck.c: static void check_pw_file (bool *errors, bool *changed)
                 * If this is a NIS line, skip it. You can't "know" what NIS
                 * is going to do without directly asking NIS ...
                 */
    @@ src/pwck.c: static void check_pw_file (int *errors, bool *changed)
                        continue;
                }
      
    -@@ src/pwck.c: static void check_spw_file (int *errors, bool *changed)
    +@@ src/pwck.c: static void check_spw_file (bool *errors, bool *changed)
                 * If this is a NIS line, skip it. You can't "know" what NIS
                 * is going to do without directly asking NIS ...
                 */

}
char *val;

cp = strprefix(cp, ",") ?: cp;

Check notice

Code scanning / CodeQL

For loop variable changed in body Note

Loop counters should not be modified in the body of the
loop
.
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.

1 participant