From fe5806254790edbd482a4b00b267ef643fdc223b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 22 Aug 2018 12:58:24 -0600 Subject: [PATCH] Cast uid/gid to unsigned int before printing. --- plugins/sudoers/policy.c | 2 +- plugins/sudoers/timestamp.c | 2 +- plugins/sudoers/visudo.c | 5 +++-- src/sudo_edit.c | 13 +++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/sudoers/policy.c b/plugins/sudoers/policy.c index afadd0e59..879d2b522 100644 --- a/plugins/sudoers/policy.c +++ b/plugins/sudoers/policy.c @@ -613,7 +613,7 @@ sudoers_policy_exec_setup(char *argv[], char *envp[], mode_t cmnd_umask, /* On BSD systems the effective gid is the first group in the list. */ egid = runas_gr ? (unsigned int)runas_gr->gr_gid : (unsigned int)runas_pw->pw_gid; - len = snprintf(cp, glsize - (cp - gid_list), "%u", egid); + len = snprintf(cp, glsize - (cp - gid_list), "%u", (unsigned int)egid); if (len < 0 || (size_t)len >= glsize - (cp - gid_list)) { sudo_warnx(U_("internal error, %s overflow"), __func__); free(gid_list); diff --git a/plugins/sudoers/timestamp.c b/plugins/sudoers/timestamp.c index b74a63e8b..7a854a35a 100644 --- a/plugins/sudoers/timestamp.c +++ b/plugins/sudoers/timestamp.c @@ -85,7 +85,7 @@ ts_match_record(struct timestamp_entry *key, struct timestamp_entry *entry, if (!ISSET(key->flags, TS_ANYUID) && entry->auth_uid != key->auth_uid) { sudo_debug_printf(SUDO_DEBUG_DEBUG, "%s:%u record uid mismatch (want %u, got %u)", __func__, recno, - key->auth_uid, entry->auth_uid); + (unsigned int)key->auth_uid, (unsigned int)entry->auth_uid); debug_return_bool(false); } if (entry->type != key->type) { diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 533c952e8..0366cd40a 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -721,7 +721,8 @@ install_sudoers(struct sudoersfile *sp, bool oldperms) } else { if (chown(sp->tpath, sudoers_uid, sudoers_gid) != 0) { sudo_warn(U_("unable to set (uid, gid) of %s to (%u, %u)"), - sp->tpath, sudoers_uid, sudoers_gid); + sp->tpath, (unsigned int)sudoers_uid, + (unsigned int)sudoers_gid); goto done; } if (chmod(sp->tpath, sudoers_mode) != 0) { @@ -878,7 +879,7 @@ check_owner(const char *path, bool quiet) if (!quiet) { fprintf(stderr, _("%s: wrong owner (uid, gid) should be (%u, %u)\n"), - path, sudoers_uid, sudoers_gid); + path, (unsigned int)sudoers_uid, (unsigned int)sudoers_gid); } } if ((sb.st_mode & ALLPERMS) != sudoers_mode) { diff --git a/src/sudo_edit.c b/src/sudo_edit.c index acf028050..34ef0aabd 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -62,7 +62,8 @@ switch_user(uid_t euid, gid_t egid, int ngroups, GETGROUPS_T *groups) debug_decl(switch_user, SUDO_DEBUG_EDIT) sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, - "set uid:gid to %u:%u(%u)", euid, egid, ngroups ? groups[0] : egid); + "set uid:gid to %u:%u(%u)", (unsigned int)euid, (unsigned int)egid, + ngroups ? (unsigned int)groups[0] : (unsigned int)egid); /* When restoring root, change euid first; otherwise change it last. */ if (euid == ROOT_UID) { @@ -77,7 +78,7 @@ switch_user(uid_t euid, gid_t egid, int ngroups, GETGROUPS_T *groups) } if (euid != ROOT_UID) { if (seteuid(euid) != 0) - sudo_fatal("seteuid(%d)", (int)euid); + sudo_fatal("seteuid(%u)", (unsigned int)euid); } errno = serrno; @@ -606,9 +607,9 @@ sudo_edit_create_tfiles(struct command_details *command_details, tf[j].osize = sb.st_size; mtim_get(&sb, tf[j].omtim); sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, - "seteuid(%u)", user_details.uid); + "seteuid(%u)", (unsigned int)user_details.uid); if (seteuid(user_details.uid) != 0) - sudo_fatal("seteuid(%d)", (int)user_details.uid); + sudo_fatal("seteuid(%u)", (unsigned int)user_details.uid); tfd = sudo_edit_mktemp(tf[j].ofile, &tf[j].tfile); sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, "seteuid(%u)", ROOT_UID); @@ -680,9 +681,9 @@ sudo_edit_copy_tfiles(struct command_details *command_details, for (i = 0; i < nfiles; i++) { rc = -1; sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, - "seteuid(%u)", user_details.uid); + "seteuid(%u)", (unsigned int)user_details.uid); if (seteuid(user_details.uid) != 0) - sudo_fatal("seteuid(%d)", (int)user_details.uid); + sudo_fatal("seteuid(%u)", (unsigned int)user_details.uid); tfd = sudo_edit_open(tf[i].tfile, O_RDONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, NULL); if (tfd != -1) -- 2.40.0