Avoid some PVS-Studio false positives.

This commit is contained in:
Todd C. Miller
2018-10-19 13:35:20 -06:00
parent e9dec0f8d2
commit 8c94175ba1
5 changed files with 10 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ sudo_new_key_val_v1(const char *key, const char *val)
debug_decl(sudo_new_key_val, SUDO_DEBUG_UTIL) debug_decl(sudo_new_key_val, SUDO_DEBUG_UTIL)
cp = str = malloc(key_len + 1 + val_len + 1); cp = str = malloc(key_len + 1 + val_len + 1);
if (str != NULL) { if (cp != NULL) {
memcpy(cp, key, key_len); memcpy(cp, key, key_len);
cp += key_len; cp += key_len;
*cp++ = '='; *cp++ = '=';

View File

@@ -162,13 +162,14 @@ expand_iolog_path(const char *prefix, const char *dir, const char *file,
/* Expanded path must be <= PATH_MAX */ /* Expanded path must be <= PATH_MAX */
if (prefix != NULL) if (prefix != NULL)
prelen = strlen(prefix); prelen = strlen(prefix);
dst = path = malloc(prelen + PATH_MAX); path = malloc(prelen + PATH_MAX);
if (path == NULL) { if (path == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto bad; goto bad;
} }
*path = '\0'; *path = '\0';
pathend = path + prelen + PATH_MAX; pathend = path + prelen + PATH_MAX;
dst = path;
/* Copy prefix, if present. */ /* Copy prefix, if present. */
if (prefix != NULL) { if (prefix != NULL) {

View File

@@ -71,12 +71,12 @@ linux_audit_command(char *argv[], int result)
/* Convert argv to a flat string. */ /* Convert argv to a flat string. */
for (size = 0, av = argv; *av != NULL; av++) for (size = 0, av = argv; *av != NULL; av++)
size += strlen(*av) + 1; size += strlen(*av) + 1;
command = cp = malloc(size); command = malloc(size);
if (command == NULL) { if (command == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto done; goto done;
} }
for (av = argv; *av != NULL; av++) { for (av = argv, cp = command; *av != NULL; av++) {
n = strlcpy(cp, *av, size - (cp - command)); n = strlcpy(cp, *av, size - (cp - command));
if (n >= size - (cp - command)) { if (n >= size - (cp - command)) {
sudo_warnx(U_("internal error, %s overflow"), __func__); sudo_warnx(U_("internal error, %s overflow"), __func__);

View File

@@ -104,11 +104,12 @@ fill_cmnd(const char *src, size_t len)
arg_len = arg_size = 0; arg_len = arg_size = 0;
dst = sudoerslval.command.cmnd = malloc(len + 1); dst = sudoerslval.command.cmnd = malloc(len + 1);
if (sudoerslval.command.cmnd == NULL) { if (dst == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
sudoerserror(NULL); sudoerserror(NULL);
debug_return_bool(false); debug_return_bool(false);
} }
sudoerslval.command.args = NULL;
/* Copy the string and collapse any escaped sudo-specific characters. */ /* Copy the string and collapse any escaped sudo-specific characters. */
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
@@ -119,7 +120,6 @@ fill_cmnd(const char *src, size_t len)
} }
*dst = '\0'; *dst = '\0';
sudoerslval.command.args = NULL;
debug_return_bool(true); debug_return_bool(true);
} }

View File

@@ -59,16 +59,18 @@ add_preserved_fd(struct preserved_fd_list *pfds, int fd)
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
"fd %d already preserved", fd); "fd %d already preserved", fd);
free(pfd_new); free(pfd_new);
pfd_new = NULL;
break; break;
} }
if (fd < pfd->highfd) { if (fd < pfd->highfd) {
TAILQ_INSERT_BEFORE(pfd, pfd_new, entries); TAILQ_INSERT_BEFORE(pfd, pfd_new, entries);
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
"preserving fd %d", fd); "preserving fd %d", fd);
pfd_new = NULL;
break; break;
} }
} }
if (pfd == NULL) { if (pfd_new != NULL) {
TAILQ_INSERT_TAIL(pfds, pfd_new, entries); TAILQ_INSERT_TAIL(pfds, pfd_new, entries);
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
"preserving fd %d", fd); "preserving fd %d", fd);