Bug 158794

Summary: <default> line has been ignored in /etc/newsyslog.conf
Product: Base System Reporter: Ken-ichi EZURA <k.ezura>
Component: binAssignee: David Bright <dab>
Status: Closed FIXED    
Severity: Affects Only Me CC: dab, freebsd
Priority: Normal Flags: dab: mfc-stable12+
dab: mfc-stable11+
dab: mfc-stable10+
Version: 8.2-RELEASE   
Hardware: Any   
OS: Any   

Description Ken-ichi EZURA 2011-07-11 08:50:08 UTC
/etc/newsyslog.conf is follows,

<default>                               640  400   *    @T00  J
/var/log/all.log                        600  7     *    @T00  J
/var/log/amd.log                        644  7     100  *     J
/var/log/auth.log                       640  3     *    @01T00 JC
/var/log/console.log                    600  10    5000 *     JC
/var/log/cron                           600  10    100  *     JC
/var/log/daily.log                      640  7     *    @T00  JN
/var/log/debug.log                      600  7     100  *     J
/var/log/kerberos.log                   600  7     100  *     J
/var/log/lpd-errs                       644  7     100  *     JC
/var/log/maillog                        640  30    *    @T00  JC
/var/log/messages                       644  10    1000 *     JC
/var/log/monthly.log                    640  12    *    $M1D0 JN
/var/log/pflog                          600  3     100  *     JB    /var/run/pflogd.pid
/var/log/ppp.log        root:network    640  3     100  *     JC
/var/log/security                       640  10    1000 *     JC
/var/log/sendmail.st                    640  10    *    168   B
/var/log/slip.log       root:network    640  3     100  *     JC
/var/log/weekly.log                     640  5     1    $W6D0 JN
/var/log/wtmp                           644  12    *    @01T05 B
/var/log/xferlog                        600  7     1000 *     JC
/var/log/daemonlog                      640  10    1000 *     JC
/var/log/console.log                    640  10    100  *     JC



old version newsyslog.c (may be 8.1-RELEASE)
$FreeBSD: src/usr.sbin/newsyslog/newsyslog.c,v 1.108.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $

It's ok when run this version.

# newsyslog -n -v -F /var/log/hoge.txt
/var/log/hoge.txt <400J>: --> trimming log....
        rm -f /var/log/hoge.txt.400
        rm -f /var/log/hoge.txt.400.gz
        rm -f /var/log/hoge.txt.400.bz2
        ln /var/log/hoge.txt /var/log/hoge.txt.0
        chmod 640 /var/log/hoge.txt.0
Start new log...
        mktemp /var/log/hoge.txt.zXXXXXX
        chmod 640 /var/log/hoge.txt.zXXXXXX
        mv /var/log/hoge.txt.zXXXXXX /var/log/hoge.txt
Signal all daemon process(es)...
        kill -1 86622           # /var/run/syslog.pid
        sleep 10
Compress all rotated log file(s)...
        bzip2 /var/log/hoge.txt.0
        chmod 640 /var/log/hoge.txt.0.bz2



However, 8.2-RELEASE newsyslog.c
$FreeBSD: src/usr.sbin/newsyslog/newsyslog.c,v 1.108.2.6.2.2 2011/01/07 18:33:26 brian Exp $

<default> line has been ignored.

# newsyslog -n -v -F /var/log/hoge.txt
Processing /etc/newsyslog.conf
/var/log/hoge.txt <3>: size (Kb): 0 [50] --> trimming log....
        rm -f /var/log/hoge.txt.3
        rm -f /var/log/hoge.txt.3.gz
        rm -f /var/log/hoge.txt.3.bz2
        ln /var/log/hoge.txt /var/log/hoge.txt.0
        chmod 600 /var/log/hoge.txt.0
Start new log...
        mktemp /var/log/hoge.txt.zXXXXXX
        chmod 600 /var/log/hoge.txt.zXXXXXX
        mv /var/log/hoge.txt.zXXXXXX /var/log/hoge.txt
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:16 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 2 Airell 2018-01-10 08:31:47 UTC
Running newsyslog with -vvvvv shows a 'default' <default> entry will be made even if a <default> entry is present in a log file:

/etc/newsyslog.conf.d/default.conf
# logfilename          [owner:group]    mode count size when  flags
<default>                               640  7     100  @T00  JN
somelog.log                             640  7     100  @T00  JN


Processing /etc/newsyslog.conf.d/default.conf
        --> [creating entry for <default>]     <-- This is <default> from conf
        --> [creating entry for somelog.log]   <-- This is somelog.log from conf
        --> [creating entry for <default>]     <-- This is 'default' <default>
        + No entry matched /var/log/nginx/nginx-access-global.log  (will use <default>)
...
/var/log/nginx/nginx-access-global.log <3>: size (Kb): 7 [50] --> skipping


Above example shows the size rotation is 50, not 100. So it's probably taking the last <default> entry, which is the one automatically created:


When removing the <default> line from the config, it shows the 'default' <default> entry be made:

Processing /etc/newsyslog.conf.d/default.conf
        --> [creating entry for somelog.log]   <-- This is somelog.log from conf
        --> [creating entry for <default>]     <-- This is 'default' <default>
        + No entry matched /var/log/nginx/nginx-access-global.log  (will use <default>)
...
/var/log/nginx/nginx-access-global.log <3>: size (Kb): 7 [50] --> skipping


Regards, Airell.
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-02-08 13:54:29 UTC
A commit references this bug:

Author: dab
Date: Fri Feb  8 13:54:17 UTC 2019
New revision: 343906
URL: https://svnweb.freebsd.org/changeset/base/343906

Log:
  Fix several Coverity-detected issues in newsyslog.

  - CID 1394815, CID 1305673: Dereference before null check - memory was
    allocated and the allocation checked for NULL with a call to errx()
    if it failed. Code below that was guaranteed that the pointer was
    non-NULL, but there was another check for NULL at the exit of the
    function (after the memory had already been referenced). Eliminate
    the useless NULL check.

  - CID 1007454, CID 1007453: Resource leak - The result of a strdup()
    was stored in a global variable and not freed before program exit.

  - CID 1007452: Resource leak - Storage intended to be allocated and
    returned to the caller was never freed. This was the result of a
    regression in the function signature introduced in r208648 (2010)
    (thanks for that find, @cem!). Fixed by altering the function
    signature and passing the allocated memory to the caller as
    intended. This also fixes PR158794.

  - CID 1008620: Logically dead code in newsyslog.c - This was a direct
    result of CID 1007452. Since the memory allocated as described there
    was not returned to the caller, a subsequent check for the memory
    having been allocated was dead code. Returning the memory
    re-animates the code that is the subject of this CID.

  - CID 1006131: Unused value - in parsing a configuration file, a
    pointer to the end of the last field was saved, but not used after
    that. Rewrite to use the pointer value. This could have been fixed
    by avoiding the assignment altogether, but this solutions more
    closely follows the pattern used in the preceding code.

  PR:		158794
  Reported by:	Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)
  Reviewed by:	cem, markj
  MFC after:	1 week
  Sponsored by:	Dell EMC Isilon

Changes:
  head/usr.sbin/newsyslog/newsyslog.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-02-22 15:32:37 UTC
A commit references this bug:

Author: dab
Date: Fri Feb 22 15:31:51 UTC 2019
New revision: 344470
URL: https://svnweb.freebsd.org/changeset/base/344470

Log:
  Fix several Coverity-detected issues in newsyslog.

  - CID 1394815, CID 1305673: Dereference before null check - memory was
    allocated and the allocation checked for NULL with a call to errx()
    if it failed. Code below that was guaranteed that the pointer was
    non-NULL, but there was another check for NULL at the exit of the
    function (after the memory had already been referenced). Eliminate
    the useless NULL check.

  - CID 1007452: Resource leak - Storage intended to be allocated and
    returned to the caller was never freed. This was the result of a
    regression in the function signature introduced in r208648 (2010)
    (thanks for that find, @cem!). Fixed by altering the function
    signature and passing the allocated memory to the caller as
    intended. This also fixes PR158794.

  - CID 1008620: Logically dead code in newsyslog.c - This was a direct
    result of CID 1007452. Since the memory allocated as described there
    was not returned to the caller, a subsequent check for the memory
    having been allocated was dead code. Returning the memory
    re-animates the code that is the subject of this CID.

  - CID 1006131: Unused value - in parsing a configuration file, a
    pointer to the end of the last field was saved, but not used after
    that. Rewrite to use the pointer value. This could have been fixed
    by avoiding the assignment altogether, but this solutions more
    closely follows the pattern used in the preceding code.

  PR:		158794
  Reported by:	Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)
  Reviewed by:	cem, markj
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D19105

Changes:
  head/usr.sbin/newsyslog/newsyslog.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-03-07 13:11:01 UTC
A commit references this bug:

Author: dab
Date: Thu Mar  7 13:10:34 UTC 2019
New revision: 344880
URL: https://svnweb.freebsd.org/changeset/base/344880

Log:
  MFC r344470:

  Fix several Coverity-detected issues in newsyslog.

  - CID 1394815, CID 1305673: Dereference before null check - memory was
    allocated and the allocation checked for NULL with a call to errx()
    if it failed. Code below that was guaranteed that the pointer was
    non-NULL, but there was another check for NULL at the exit of the
    function (after the memory had already been referenced). Eliminate
    the useless NULL check.

  - CID 1007452: Resource leak - Storage intended to be allocated and
    returned to the caller was never freed. This was the result of a
    regression in the function signature introduced in r208648 (2010)
    (thanks for that find, @cem!). Fixed by altering the function
    signature and passing the allocated memory to the caller as
    intended. This also fixes PR158794.

  - CID 1008620: Logically dead code in newsyslog.c - This was a direct
    result of CID 1007452. Since the memory allocated as described there
    was not returned to the caller, a subsequent check for the memory
    having been allocated was dead code. Returning the memory
    re-animates the code that is the subject of this CID.

  - CID 1006131: Unused value - in parsing a configuration file, a
    pointer to the end of the last field was saved, but not used after
    that. Rewrite to use the pointer value. This could have been fixed
    by avoiding the assignment altogether, but this solutions more
    closely follows the pattern used in the preceding code.

  PR:             158794
  Reported by:    Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)

  Sponsored by:	Dell EMC Isilon

Changes:
_U  stable/12/
  stable/12/usr.sbin/newsyslog/newsyslog.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2019-03-07 13:11:04 UTC
A commit references this bug:

Author: dab
Date: Thu Mar  7 13:10:49 UTC 2019
New revision: 344881
URL: https://svnweb.freebsd.org/changeset/base/344881

Log:
  MFC r344470:

  Fix several Coverity-detected issues in newsyslog.

  - CID 1394815, CID 1305673: Dereference before null check - memory was
    allocated and the allocation checked for NULL with a call to errx()
    if it failed. Code below that was guaranteed that the pointer was
    non-NULL, but there was another check for NULL at the exit of the
    function (after the memory had already been referenced). Eliminate
    the useless NULL check.

  - CID 1007452: Resource leak - Storage intended to be allocated and
    returned to the caller was never freed. This was the result of a
    regression in the function signature introduced in r208648 (2010)
    (thanks for that find, @cem!). Fixed by altering the function
    signature and passing the allocated memory to the caller as
    intended. This also fixes PR158794.

  - CID 1008620: Logically dead code in newsyslog.c - This was a direct
    result of CID 1007452. Since the memory allocated as described there
    was not returned to the caller, a subsequent check for the memory
    having been allocated was dead code. Returning the memory
    re-animates the code that is the subject of this CID.

  - CID 1006131: Unused value - in parsing a configuration file, a
    pointer to the end of the last field was saved, but not used after
    that. Rewrite to use the pointer value. This could have been fixed
    by avoiding the assignment altogether, but this solutions more
    closely follows the pattern used in the preceding code.

  PR:             158794
  Reported by:    Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)

  Sponsored by:	Dell EMC Isilon

Changes:
_U  stable/11/
  stable/11/usr.sbin/newsyslog/newsyslog.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2019-03-07 13:12:07 UTC
A commit references this bug:

Author: dab
Date: Thu Mar  7 13:11:01 UTC 2019
New revision: 344882
URL: https://svnweb.freebsd.org/changeset/base/344882

Log:
  MFC r344470:

  Fix several Coverity-detected issues in newsyslog.

  - CID 1394815, CID 1305673: Dereference before null check - memory was
    allocated and the allocation checked for NULL with a call to errx()
    if it failed. Code below that was guaranteed that the pointer was
    non-NULL, but there was another check for NULL at the exit of the
    function (after the memory had already been referenced). Eliminate
    the useless NULL check.

  - CID 1007452: Resource leak - Storage intended to be allocated and
    returned to the caller was never freed. This was the result of a
    regression in the function signature introduced in r208648 (2010)
    (thanks for that find, @cem!). Fixed by altering the function
    signature and passing the allocated memory to the caller as
    intended. This also fixes PR158794.

  - CID 1008620: Logically dead code in newsyslog.c - This was a direct
    result of CID 1007452. Since the memory allocated as described there
    was not returned to the caller, a subsequent check for the memory
    having been allocated was dead code. Returning the memory
    re-animates the code that is the subject of this CID.

  - CID 1006131: Unused value - in parsing a configuration file, a
    pointer to the end of the last field was saved, but not used after
    that. Rewrite to use the pointer value. This could have been fixed
    by avoiding the assignment altogether, but this solutions more
    closely follows the pattern used in the preceding code.

  PR:             158794
  Reported by:    Coverity, Ken-ichi EZURA <k.ezura@gmail.com> (PR158794)

  Sponsored by:	Dell EMC Isilon

Changes:
_U  stable/10/
  stable/10/usr.sbin/newsyslog/newsyslog.c