Skip to content

Commit 19b967c

Browse files
committed
iolog_read_timing_record: require a newline at the end of each record
If a timing file line is larger than LINE_MAX it will be read as multiple lines. Check for this and error out before trying to parse the line.
1 parent 30dc0f8 commit 19b967c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/iolog/iolog_timing.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
252252
{
253253
char line[LINE_MAX];
254254
const char *errstr;
255+
char *nl;
255256
debug_decl(iolog_read_timing_record, SUDO_DEBUG_UTIL);
256257

257258
/* Read next record from timing file. */
@@ -263,12 +264,23 @@ iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
263264
debug_return_int(-1);
264265
}
265266

267+
/*
268+
* All timing file records must end with a newline.
269+
* A missing newline may indicate a line longer than LINE_MAX.
270+
*/
271+
nl = strchr(line, '\n');
272+
if (nl == NULL) {
273+
goto invalid;
274+
}
275+
*nl = '\0';
276+
266277
/* Parse timing file record. */
267-
line[strcspn(line, "\n")] = '\0';
268278
if (!iolog_parse_timing(line, timing)) {
269-
sudo_warnx(U_("invalid timing file line: %s"), line);
270-
debug_return_int(-1);
279+
goto invalid;
271280
}
272281

273282
debug_return_int(0);
283+
invalid:
284+
sudo_warnx(U_("invalid timing file line: %s"), line);
285+
debug_return_int(-1);
274286
}

0 commit comments

Comments
 (0)