Skip to content

Commit af4634a

Browse files
committed
expand_include: initialize dst_size to 1 to quiet coverity warning
This could only be an issue if the sudoers file was an empty string, which is not possible.
1 parent 34a3c84 commit af4634a

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

plugins/sudoers/toke.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@ char *yytext;
32623262
/*
32633263
* SPDX-License-Identifier: ISC
32643264
*
3265-
* Copyright (c) 1996, 1998-2005, 2007-2024
3265+
* Copyright (c) 1996, 1998-2005, 2007-2025
32663266
* Todd C. Miller <[email protected]>
32673267
*
32683268
* Permission to use, copy, modify, and distribute this software for any
@@ -5982,14 +5982,15 @@ expand_include(const char *src, const char *host)
59825982
* If the current sudoers file was opened via a colon-separated path,
59835983
* use the same path when opening src.
59845984
*/
5985-
dst_size = 0;
5985+
dst_size = 1;
59865986
for (cp = sudo_strsplit(path, path_end, ":", &ep); cp != NULL;
59875987
cp = sudo_strsplit(NULL, path_end, ":", &ep)) {
59885988
char *dirend = memrchr(cp, '/', (size_t)(ep - cp));
59895989
if (dirend != NULL) {
5990+
/* Include space for trailing '/' separator. */
59905991
dst_size += (size_t)(dirend - cp) + 1;
59915992
}
5992-
/* Includes space for ':' separator and NUL terminator. */
5993+
/* Includes space for expanded host and ':' separator. */
59935994
dst_size += src_len + (nhost * strlen(host)) - (nhost * 2) + 1;
59945995
}
59955996

plugins/sudoers/toke.l

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* SPDX-License-Identifier: ISC
44
*
5-
* Copyright (c) 1996, 1998-2005, 2007-2024
5+
* Copyright (c) 1996, 1998-2005, 2007-2025
66
* Todd C. Miller <[email protected]>
77
*
88
* Permission to use, copy, modify, and distribute this software for any
@@ -1203,14 +1203,15 @@ expand_include(const char *src, const char *host)
12031203
* If the current sudoers file was opened via a colon-separated path,
12041204
* use the same path when opening src.
12051205
*/
1206-
dst_size = 0;
1206+
dst_size = 1;
12071207
for (cp = sudo_strsplit(path, path_end, ":", &ep); cp != NULL;
12081208
cp = sudo_strsplit(NULL, path_end, ":", &ep)) {
12091209
char *dirend = memrchr(cp, '/', (size_t)(ep - cp));
12101210
if (dirend != NULL) {
1211+
/* Include space for trailing '/' separator. */
12111212
dst_size += (size_t)(dirend - cp) + 1;
12121213
}
1213-
/* Includes space for ':' separator and NUL terminator. */
1214+
/* Includes space for expanded host and ':' separator. */
12141215
dst_size += src_len + (nhost * strlen(host)) - (nhost * 2) + 1;
12151216
}
12161217

0 commit comments

Comments
 (0)