[DTrace-devel] [PATCH 13/17] fbt, syscall: use getline(), not fgets()
Nick Alcock
nick.alcock at oracle.com
Wed Sep 7 11:17:25 UTC 2022
On 1 Sep 2022, Eugene Loh via DTrace-devel verbalised:
> On 8/10/22 18:07, Nick Alcock via DTrace-devel wrote:
>> diff --git a/libdtrace/dt_prov_fbt.c b/libdtrace/dt_prov_fbt.c
>> @@ -77,27 +77,16 @@ static int populate(dtrace_hdl_t *dtp)
>> - while (fgets(buf, sizeof(buf), f)) {
>> + while (getline(&buf, &n, f) >= 0) {
>> /*
>> * Here buf is either "funcname\n" or "funcname [modname]\n".
>> + * The last line may not have a linefeed.
>> */
>> p = strchr(buf, '\n');
>> if (p) {
>> *p = '\0';
>> if (p > buf && *(--p) == ']')
>> *p = '\0';
>> - } else {
>> - /*
>> - * If we didn't see a newline, the line was too long.
>> - * Report it, and skip until the end of the line.
>> - */
>> - fprintf(stderr, "%s: Line too long: %s\n",
>> - PROBE_LIST, buf);
>> -
>> - do
>> - fgets(buf, sizeof(buf), f);
>> - while (strchr(buf, '\n') == NULL);
>> - continue;
>> }
>
> Is there a pre-existing problem here? What if the last line does not have a linefeed? Do we then fail to strip off the trailing
> ']'?
Oof. Yeah. However, that can only happen if the kernel truncates the
output, in which case it's pretty unlikely we'll get a trailing ]
anyway. If present, it would be the very last character before the
trailing linefeed, after all. So this is harmless, I think.
--
NULL && (void)
More information about the DTrace-devel
mailing list