syslogd fails to recognize non alphanumeric program names

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

syslogd fails to recognize non alphanumeric program names

kawashima_james
Hi,

syslogd uses isalnum(3) to extract the program name from log lines, so it is not possible to filter for programs with - or _ in their names like below

!my-program
# will never match because syslogd extracts only "my"

please kindly tell me if this is not a bug (if I should stop using underscores or hyphens in my program names)

I do not have time to submit patches, so I am using recurring donations instead.
Hope you will understand.

Always thank you for your work,
Kawashima

Reply | Threaded
Open this post in threaded view
|

Re: syslogd fails to recognize non alphanumeric program names

Ingo Schwarze
Hello Kawashima-san,

kawashima_james wrote on Sat, Jan 12, 2019 at 02:27:55AM +0900:

> syslogd uses isalnum(3) to extract the program name from log lines,
> so it is not possible to filter for programs with -

If i read the source code in syslogd.c correctly, '-' is already
supported, see below.

> or _ in their names like below
>
> !my-program
> # will never match because syslogd extracts only "my"
>
> please kindly tell me if this is not a bug (if I should stop using
> underscores or hyphens in my program names)

There is nothing wrong with underscores in program names.
Actually, they appear to be quite common:

  $ ls {/usr,}/{s,}bin/*_*

The same is true for '.'.

So i'm proposing the following patch.
Lightly tested, but it does not look dangerous,
so i'm looking for OKs.

Thanks you for reporting and for your support!

Yours,
  Ingo


Index: syslogd.c
===================================================================
RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.257
diff -u -p -r1.257 syslogd.c
--- syslogd.c 29 Nov 2018 21:10:51 -0000 1.257
+++ syslogd.c 12 Jan 2019 17:35:14 -0000
@@ -1796,7 +1796,8 @@ logline(int pri, int flags, char *from,
  msglen--;
  }
  for (i = 0; i < NAME_MAX; i++) {
- if (!isalnum((unsigned char)msg[i]) && msg[i] != '-')
+ if (!isalnum((unsigned char)msg[i]) &&
+    msg[i] != '-' && msg[i] != '.' && msg[i] != '_')
  break;
  prog[i] = msg[i];
  }

Reply | Threaded
Open this post in threaded view
|

Re: syslogd fails to recognize non alphanumeric program names

kawashima_james
Ingo

indeed hyphens were OK, my programs are actually using underscores.

Patch seems fine to me, thank you very much. (I do not know how to submit patches so let me let competent people do it to not waste time)

Kawashima

2019/01/13 2:45、Ingo Schwarze <[hidden email]>のメール:

> Hello Kawashima-san,
>
> kawashima_james wrote on Sat, Jan 12, 2019 at 02:27:55AM +0900:
>
>> syslogd uses isalnum(3) to extract the program name from log lines,
>> so it is not possible to filter for programs with -
>
> If i read the source code in syslogd.c correctly, '-' is already
> supported, see below.
>
>> or _ in their names like below
>>
>> !my-program
>> # will never match because syslogd extracts only "my"
>>
>> please kindly tell me if this is not a bug (if I should stop using
>> underscores or hyphens in my program names)
>
> There is nothing wrong with underscores in program names.
> Actually, they appear to be quite common:
>
>  $ ls {/usr,}/{s,}bin/*_*
>
> The same is true for '.'.
>
> So i'm proposing the following patch.
> Lightly tested, but it does not look dangerous,
> so i'm looking for OKs.
>
> Thanks you for reporting and for your support!
>
> Yours,
>  Ingo
>
>
> Index: syslogd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.257
> diff -u -p -r1.257 syslogd.c
> --- syslogd.c    29 Nov 2018 21:10:51 -0000    1.257
> +++ syslogd.c    12 Jan 2019 17:35:14 -0000
> @@ -1796,7 +1796,8 @@ logline(int pri, int flags, char *from,
>        msglen--;
>    }
>    for (i = 0; i < NAME_MAX; i++) {
> -        if (!isalnum((unsigned char)msg[i]) && msg[i] != '-')
> +        if (!isalnum((unsigned char)msg[i]) &&
> +            msg[i] != '-' && msg[i] != '.' && msg[i] != '_')
>            break;
>        prog[i] = msg[i];
>    }

Reply | Threaded
Open this post in threaded view
|

Re: syslogd fails to recognize non alphanumeric program names

Ingo Schwarze
Hello Kawashima-san,

kawashima_james wrote on Sun, Jan 13, 2019 at 01:43:42PM +0900:

> indeed hyphens were OK, my programs are actually using underscores.
> Patch seems fine to me, thank you very much.

Thank you very much for reporting and testing!

I committed the patch and also updated the documentation, see below.

> (I do not know how to submit patches so let me let competent people
> do it to not waste time)

It is perfectly understood that many people are very short on time,
and reporting issues in such a clear way is appreciated even without
included patches.

Then again, in case you ever *want* to learn submitting patches,
it will no longer be hard for you.  It appears you are already able
to do the hardest part: testing patches.  Once you know that, the
rest is no longer difficult:

 $ cd # to the source directory in question
 $ cvs up -dP
 $ vi # the file in question as needed
 $ ... # compile and test thoroughly
 $ cvs up -dP # again
 $ cvs diff -Nup > tmp.patch

and then include the patch verbatim into the mail body, for example
with the vi(1) :r command, *not* pasting it with a mouse.

Yours,
  Ingo


CVSROOT: /cvs
Module name: src
Changes by: [hidden email] 2019/01/13 03:42:51

Modified files:
        usr.sbin/syslogd: syslogd.c

Log message:
When parsing log lines in order to select syslog.conf(5) line blocks, support
program names containing period ('.') and underscore ('_') ASCII characters.
Missing feature reported by and patch tested by
Kawashima underscore James at yahoo dot co dot jp.
"Makes sense." deraadt@

>> Index: syslogd.c
>> ===================================================================
>> RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
>> retrieving revision 1.257
>> diff -u -p -r1.257 syslogd.c
>> --- syslogd.c    29 Nov 2018 21:10:51 -0000    1.257
>> +++ syslogd.c    12 Jan 2019 17:35:14 -0000
>> @@ -1796,7 +1796,8 @@ logline(int pri, int flags, char *from,
>>        msglen--;
>>    }
>>    for (i = 0; i < NAME_MAX; i++) {
>> -        if (!isalnum((unsigned char)msg[i]) && msg[i] != '-')
>> +        if (!isalnum((unsigned char)msg[i]) &&
>> +            msg[i] != '-' && msg[i] != '.' && msg[i] != '_')
>>            break;
>>        prog[i] = msg[i];
>>    }


CVSROOT: /cvs
Module name: src
Changes by: [hidden email] 2019/01/13 04:07:47

Modified files:
        usr.sbin/syslogd: syslog.conf.5

Log message:
document how program names are extracted from log lines
in order to select syslog.conf(5) line blocks

Index: syslog.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/syslogd/syslog.conf.5,v
retrieving revision 1.38
diff -u -r1.38 syslog.conf.5
--- syslog.conf.5 23 Jul 2018 19:02:49 -0000 1.38
+++ syslog.conf.5 13 Jan 2019 11:03:33 -0000
@@ -158,6 +158,15 @@
 the action specified in the
 .Em action
 field will be taken.
+In this context,
+.Xr ascii 7
+letters, digits, hyphens
+.Pq Sq - ,
+periods
+.Pq Sq \&. ,
+and underscores
+.Pq Sq _
+can be contained in a word; other bytes end the word.
 .Pp
 Multiple
 .Em selectors

Reply | Threaded
Open this post in threaded view
|

Re: syslogd fails to recognize non alphanumeric program names

kawashima_james
Ingo

thank you for the instructions. In fact in did not test, just review the patch, sorry for the misunderstanding.

By the way, eventually I would like to use the SIM card in my Let's Note laptop (qualcomm snapdragon chip) in order to use LTE, so maybe I will write some patch myself some day! (I will post about this when I have more time)

Kawashima

2019/01/13 20:27、Ingo Schwarze <[hidden email]>のメール:

> Hello Kawashima-san,
>
> kawashima_james wrote on Sun, Jan 13, 2019 at 01:43:42PM +0900:
>
>> indeed hyphens were OK, my programs are actually using underscores.
>> Patch seems fine to me, thank you very much.
>
> Thank you very much for reporting and testing!
>
> I committed the patch and also updated the documentation, see below.
>
>> (I do not know how to submit patches so let me let competent people
>> do it to not waste time)
>
> It is perfectly understood that many people are very short on time,
> and reporting issues in such a clear way is appreciated even without
> included patches.
>
> Then again, in case you ever *want* to learn submitting patches,
> it will no longer be hard for you.  It appears you are already able
> to do the hardest part: testing patches.  Once you know that, the
> rest is no longer difficult:
>
> $ cd # to the source directory in question
> $ cvs up -dP
> $ vi # the file in question as needed
> $ ... # compile and test thoroughly
> $ cvs up -dP # again
> $ cvs diff -Nup > tmp.patch
>
> and then include the patch verbatim into the mail body, for example
> with the vi(1) :r command, *not* pasting it with a mouse.
>
> Yours,
>  Ingo
>
>
> CVSROOT:    /cvs
> Module name:    src
> Changes by:    [hidden email]    2019/01/13 03:42:51
>
> Modified files:
>    usr.sbin/syslogd: syslogd.c
>
> Log message:
> When parsing log lines in order to select syslog.conf(5) line blocks, support
> program names containing period ('.') and underscore ('_') ASCII characters.
> Missing feature reported by and patch tested by
> Kawashima underscore James at yahoo dot co dot jp.
> "Makes sense." deraadt@
>
>>> Index: syslogd.c
>>> ===================================================================
>>> RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
>>> retrieving revision 1.257
>>> diff -u -p -r1.257 syslogd.c
>>> --- syslogd.c    29 Nov 2018 21:10:51 -0000    1.257
>>> +++ syslogd.c    12 Jan 2019 17:35:14 -0000
>>> @@ -1796,7 +1796,8 @@ logline(int pri, int flags, char *from,
>>>       msglen--;
>>>   }
>>>   for (i = 0; i < NAME_MAX; i++) {
>>> -        if (!isalnum((unsigned char)msg[i]) && msg[i] != '-')
>>> +        if (!isalnum((unsigned char)msg[i]) &&
>>> +            msg[i] != '-' && msg[i] != '.' && msg[i] != '_')
>>>           break;
>>>       prog[i] = msg[i];
>>>   }
>
>
> CVSROOT:    /cvs
> Module name:    src
> Changes by:    [hidden email]    2019/01/13 04:07:47
>
> Modified files:
>    usr.sbin/syslogd: syslog.conf.5
>
> Log message:
> document how program names are extracted from log lines
> in order to select syslog.conf(5) line blocks
>
> Index: syslog.conf.5
> ===================================================================
> RCS file: /cvs/src/usr.sbin/syslogd/syslog.conf.5,v
> retrieving revision 1.38
> diff -u -r1.38 syslog.conf.5
> --- syslog.conf.5    23 Jul 2018 19:02:49 -0000    1.38
> +++ syslog.conf.5    13 Jan 2019 11:03:33 -0000
> @@ -158,6 +158,15 @@
> the action specified in the
> .Em action
> field will be taken.
> +In this context,
> +.Xr ascii 7
> +letters, digits, hyphens
> +.Pq Sq - ,
> +periods
> +.Pq Sq \&. ,
> +and underscores
> +.Pq Sq _
> +can be contained in a word; other bytes end the word.
> .Pp
> Multiple
> .Em selectors