Skip to content

Commit 7e34997

Browse files
committed
event/libevent2022: fix coverity issue
CID 1269841 Out-of-bounds access (OVERRUN) Correct issue. If the string being concatingated fills the remaining buffer then a \0 is written past the end of the string. In practice this should never happen but it should be fixed. I re-organized the code a bit to clear this error. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 6b93db6 commit 7e34997

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

opal/mca/event/libevent2022/libevent2022_component.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int libevent2022_register (void)
125125
const struct eventop** _eventop = eventops;
126126
char available_eventops[1024] = "none";
127127
char *help_msg = NULL;
128-
int ret, len = 1024;
128+
int ret;
129129

130130
/* Retrieve the upper level specified event system, if any.
131131
* Default to select() on OS X and poll() everywhere else because
@@ -153,17 +153,15 @@ static int libevent2022_register (void)
153153
*/
154154

155155
if (NULL != (*_eventop)) {
156-
available_eventops[0] = '\0';
157-
}
156+
const int len = sizeof (available_eventops);
157+
int cur_len = snprintf (available_eventops, len, "%s", (*(_eventop++))->name);
158158

159-
while( NULL != (*_eventop) ) {
160-
if( available_eventops[0] != '\0' ) {
161-
(void) strncat (available_eventops, ", ", len);
159+
for (int i = 1 ; eventops[i] && cur_len < len ; ++i) {
160+
cur_len += snprintf (available_eventops + cur_len, len - cur_len, ", %s",
161+
eventops[i]->name);
162162
}
163-
(void) strncat (available_eventops, (*_eventop)->name,
164-
len);
165-
_eventop++; /* go to the next available eventop */
166-
len = 1024 - strlen(available_eventops);
163+
/* ensure the available_eventops string is always NULL-terminated */
164+
available_eventops[len - 1] = '\0';
167165
}
168166

169167
#ifdef __APPLE__

0 commit comments

Comments
 (0)