diff --git a/lib/util/json.c b/lib/util/json.c index 266129dca..7279fb85f 100644 --- a/lib/util/json.c +++ b/lib/util/json.c @@ -156,7 +156,7 @@ json_append_string(struct json_container *jsonc, const char *str) break; } *cp++ = ch; - *cp++ = '\0'; + *cp = '\0'; if (!json_append_buf(jsonc, buf)) debug_return_bool(false); } diff --git a/plugins/group_file/getgrent.c b/plugins/group_file/getgrent.c index 5107acef2..f37fb0ec2 100644 --- a/plugins/group_file/getgrent.c +++ b/plugins/group_file/getgrent.c @@ -150,7 +150,7 @@ next_entry: gr.gr_mem[n] = cp; cp = strtok_r(NULL, ",", &last); } - gr.gr_mem[n++] = NULL; + gr.gr_mem[n] = NULL; } else gr.gr_mem = NULL; return &gr; diff --git a/plugins/sudoers/cvtsudoers_merge.c b/plugins/sudoers/cvtsudoers_merge.c index bd62cc068..3afd5db90 100644 --- a/plugins/sudoers/cvtsudoers_merge.c +++ b/plugins/sudoers/cvtsudoers_merge.c @@ -328,7 +328,7 @@ alias_make_unique(const char *old_name, int type, struct sudoers_parse_tree *parse_tree0, struct sudoers_parse_tree *merged_tree) { - struct sudoers_parse_tree *parse_tree = parse_tree0; + struct sudoers_parse_tree *parse_tree; char *cp, *new_name = NULL; struct alias *a; long long suffix; diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index 887d6468f..225c536f2 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -692,7 +692,7 @@ matches_env_check(const char *var, bool *full_match) } else { const char *val = strchr(var, '='); if (val != NULL) - keepit = !strpbrk(++val, "/%"); + keepit = !strpbrk(val + 1, "/%"); } } debug_return_int(keepit); diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index fc1bc7d11..ec93698f4 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -787,10 +787,8 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, } } - if (!sudoers_debug_register(plugin_path, &debug_files)) { - ret = -1; + if (!sudoers_debug_register(plugin_path, &debug_files)) goto done; - } /* If we have no command (because -V was specified) just return. */ if (argc == 0) diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c index 22c81db94..90aa35eae 100644 --- a/plugins/sudoers/ldap.c +++ b/plugins/sudoers/ldap.c @@ -204,7 +204,7 @@ static int sudo_ldap_init(LDAP **ldp, const char *host, int port) { LDAP *ld; - int ret = LDAP_CONNECT_ERROR; + int ret; debug_decl(sudo_ldap_init, SUDOERS_DEBUG_LDAP); #ifdef HAVE_LDAPSSL_INIT @@ -281,8 +281,10 @@ sudo_ldap_init(LDAP **ldp, const char *host, int port) ret = ldap_set_option(ld, LDAP_OPT_HOST_NAME, host); #else DPRINTF2("ldap_init(%s, %d)", host, port); - if ((ld = ldap_init((char *)host, port)) == NULL) + if ((ld = ldap_init((char *)host, port)) == NULL) { + ret = LDAP_LOCAL_ERROR; goto done; + } ret = LDAP_SUCCESS; #endif } diff --git a/plugins/sudoers/ldap_conf.c b/plugins/sudoers/ldap_conf.c index 7e4a2e3ad..2b566dd0e 100644 --- a/plugins/sudoers/ldap_conf.c +++ b/plugins/sudoers/ldap_conf.c @@ -509,7 +509,7 @@ sudo_krb5_ccname_path(const char *old_ccname) static bool sudo_check_krb5_ccname(const char *ccname) { - int fd = -1; + int fd; const char *ccname_path; debug_decl(sudo_check_krb5_ccname, SUDOERS_DEBUG_LDAP); diff --git a/plugins/sudoers/log_client.c b/plugins/sudoers/log_client.c index a53ffe427..783d1ff70 100644 --- a/plugins/sudoers/log_client.c +++ b/plugins/sudoers/log_client.c @@ -1085,7 +1085,7 @@ done: static bool fmt_initial_message(struct client_closure *closure) { - bool ret = true; + bool ret = false; debug_decl(fmt_initial_message, SUDOERS_DEBUG_UTIL); closure->state = closure->initial_state; @@ -1116,7 +1116,6 @@ fmt_initial_message(struct client_closure *closure) break; default: sudo_warnx(U_("%s: unexpected state %d"), __func__, closure->state); - ret = false; break; } debug_return_bool(ret); diff --git a/plugins/sudoers/match_command.c b/plugins/sudoers/match_command.c index 37d376d32..120dfa5ed 100644 --- a/plugins/sudoers/match_command.c +++ b/plugins/sudoers/match_command.c @@ -185,7 +185,7 @@ static bool open_cmnd(const char *path, const char *runchroot, const struct command_digest_list *digests, int *fdp) { - int fd = -1; + int fd; char pathbuf[PATH_MAX]; debug_decl(open_cmnd, SUDOERS_DEBUG_MATCH); diff --git a/plugins/sudoers/strvec_join.c b/plugins/sudoers/strvec_join.c index 240e0938c..ae209eb91 100644 --- a/plugins/sudoers/strvec_join.c +++ b/plugins/sudoers/strvec_join.c @@ -68,7 +68,7 @@ strvec_join(char *const argv[], char sep, size_t (*cpy)(char *, const char *, si *dst++ = sep; size--; } - *--dst = '\0'; + dst[-1] = '\0'; debug_return_str(result); } diff --git a/plugins/sudoers/tsgetgrpw.c b/plugins/sudoers/tsgetgrpw.c index 9daa3e2eb..19fb798c4 100644 --- a/plugins/sudoers/tsgetgrpw.c +++ b/plugins/sudoers/tsgetgrpw.c @@ -300,7 +300,7 @@ next_entry: gr.gr_mem[n] = cp; cp = strtok_r(NULL, ",", &last); } - gr.gr_mem[n++] = NULL; + gr.gr_mem[n] = NULL; } else gr.gr_mem = NULL; return &gr; diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 734118bac..7636b9754 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -540,7 +540,7 @@ edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc, } editor_argv[ac++] = (char *)"--"; editor_argv[ac++] = sp->tpath; - editor_argv[ac++] = NULL; + editor_argv[ac] = NULL; /* * Do the edit: diff --git a/src/sudo.c b/src/sudo.c index 2888d23a5..2405cb0f3 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -355,7 +355,7 @@ os_init_common(int argc, char *argv[], char *envp[]) static void fix_fds(void) { - int miss[3], devnull = -1; + int miss[3]; debug_decl(fix_fds, SUDO_DEBUG_UTIL); /* @@ -366,7 +366,8 @@ fix_fds(void) miss[STDOUT_FILENO] = fcntl(STDOUT_FILENO, F_GETFL, 0) == -1; miss[STDERR_FILENO] = fcntl(STDERR_FILENO, F_GETFL, 0) == -1; if (miss[STDIN_FILENO] || miss[STDOUT_FILENO] || miss[STDERR_FILENO]) { - devnull = open(_PATH_DEVNULL, O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + int devnull = + open(_PATH_DEVNULL, O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (devnull == -1) sudo_fatal(U_("unable to open %s"), _PATH_DEVNULL); if (miss[STDIN_FILENO] && dup2(devnull, STDIN_FILENO) == -1) @@ -1105,7 +1106,7 @@ format_plugin_settings(struct plugin_container *plugin) goto bad; } } - plugin_settings[++i] = NULL; + plugin_settings[i + 1] = NULL; /* Add to list of vectors to be garbage collected at exit. */ if (!gc_add(GC_VECTOR, plugin_settings))