<feed xmlns='http://www.w3.org/2005/Atom'>
<title>samba.git/lib/util/debug.c, branch talloc-2.3.4</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/'/>
<entry>
<title>debug: update comments about setup_logging()</title>
<updated>2022-05-30T11:03:47+00:00</updated>
<author>
<name>Douglas Bagnall</name>
<email>douglas.bagnall@catalyst.net.nz</email>
</author>
<published>2022-05-26T03:50:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=3567f4130d8f6193014dc7a1e06c07ecd0c98970'/>
<id>3567f4130d8f6193014dc7a1e06c07ecd0c98970</id>
<content type='text'>
Signed-off-by: Douglas Bagnall &lt;douglas.bagnall@catalyst.net.nz&gt;
Reviewed-by: Andrew Bartlett &lt;abartlet@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;

Autobuild-User(master): Andreas Schneider &lt;asn@cryptomilk.org&gt;
Autobuild-Date(master): Mon May 30 11:03:47 UTC 2022 on sn-devel-184
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Douglas Bagnall &lt;douglas.bagnall@catalyst.net.nz&gt;
Reviewed-by: Andrew Bartlett &lt;abartlet@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;

Autobuild-User(master): Andreas Schneider &lt;asn@cryptomilk.org&gt;
Autobuild-Date(master): Mon May 30 11:03:47 UTC 2022 on sn-devel-184
</pre>
</div>
</content>
</entry>
<entry>
<title>debug: add debug_traceid_set/get() interface</title>
<updated>2022-05-10T17:31:31+00:00</updated>
<author>
<name>Pavel Filipenský</name>
<email>pfilipen@redhat.com</email>
</author>
<published>2022-05-08T19:06:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=e48fc192d24a53db4209de262caec4d5b491952e'/>
<id>e48fc192d24a53db4209de262caec4d5b491952e</id>
<content type='text'>
Signed-off-by: Pavel Filipenský &lt;pfilipen@redhat.com&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;
Reviewed-by: Jeremy Allison &lt;jra@samba.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Pavel Filipenský &lt;pfilipen@redhat.com&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;
Reviewed-by: Jeremy Allison &lt;jra@samba.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>util: CID 1499409:  Memory - corruptions  (OVERLAPPING_COPY)</title>
<updated>2022-02-22T00:17:11+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2022-02-18T01:02:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=a2590298b035404d507fac1ea0e11dcd88a939fa'/>
<id>a2590298b035404d507fac1ea0e11dcd88a939fa</id>
<content type='text'>
This is quite bizarre:

*** CID 1499409:  Memory - corruptions  (OVERLAPPING_COPY)
/lib/util/debug.c: 1742 in dbghdrclass()
1736     					 sizeof(tvbuf.buf),
1737     					 "%ld seconds since the Epoch", (long)t);
1738     			}
1739     		}
1740
1741     		ensure_hostname();
&gt;&gt;&gt;     CID 1499409:  Memory - corruptions  (OVERLAPPING_COPY)
&gt;&gt;&gt;     In the call to function "snprintf", the object pointed to by argument "state.hostname" may overlap with the object pointed to by argument "state.header_str".
1742     		state.hs_len = snprintf(state.header_str,
1743     					sizeof(state.header_str),
1744     					"%s %s %s[%u]: ",
1745     					tvbuf.buf,
1746     					state.hostname,
1747     					state.prog_name,

Coverity doesn't explicitly say so but the only way this can happen is
if state.hostname is not NUL-terminated within its declared length.
ensure_hostname() and debug_set_hostname() ensure NUL-termination, but
the caching effect of ensure_hostname() probably stops Coverity from
being certain about anything.

Try making Coverity happy by using a precision to limit the number of
characters from hostname that can be used.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;
Reviewed-by: Andrew Bartlett &lt;abartlet@samba.org&gt;

Autobuild-User(master): Martin Schwenke &lt;martins@samba.org&gt;
Autobuild-Date(master): Tue Feb 22 00:17:12 UTC 2022 on sn-devel-184
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is quite bizarre:

*** CID 1499409:  Memory - corruptions  (OVERLAPPING_COPY)
/lib/util/debug.c: 1742 in dbghdrclass()
1736     					 sizeof(tvbuf.buf),
1737     					 "%ld seconds since the Epoch", (long)t);
1738     			}
1739     		}
1740
1741     		ensure_hostname();
&gt;&gt;&gt;     CID 1499409:  Memory - corruptions  (OVERLAPPING_COPY)
&gt;&gt;&gt;     In the call to function "snprintf", the object pointed to by argument "state.hostname" may overlap with the object pointed to by argument "state.header_str".
1742     		state.hs_len = snprintf(state.header_str,
1743     					sizeof(state.header_str),
1744     					"%s %s %s[%u]: ",
1745     					tvbuf.buf,
1746     					state.hostname,
1747     					state.prog_name,

Coverity doesn't explicitly say so but the only way this can happen is
if state.hostname is not NUL-terminated within its declared length.
ensure_hostname() and debug_set_hostname() ensure NUL-termination, but
the caching effect of ensure_hostname() probably stops Coverity from
being certain about anything.

Try making Coverity happy by using a precision to limit the number of
characters from hostname that can be used.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;
Reviewed-by: Andrew Bartlett &lt;abartlet@samba.org&gt;

Autobuild-User(master): Martin Schwenke &lt;martins@samba.org&gt;
Autobuild-Date(master): Tue Feb 22 00:17:12 UTC 2022 on sn-devel-184
</pre>
</div>
</content>
</entry>
<entry>
<title>lib/debug: in debug_set_logfile() call reopen_logs_internal()</title>
<updated>2021-11-11T13:49:32+00:00</updated>
<author>
<name>Ralph Boehme</name>
<email>slow@samba.org</email>
</author>
<published>2021-11-08T18:41:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=fa9d9974d068897d35539e5316f606a15e8b38de'/>
<id>fa9d9974d068897d35539e5316f606a15e8b38de</id>
<content type='text'>
This simplifies the logging API for callers that typically would want to set
logging by just setup_logging() once without bothering that typically
configuration is loaded (via some lpcfg_load*() or lp_load*() varient) which
will only then pick up the configured logfile from smb.conf without actually
applying the new logifle to the logging subsytem.

Therefor our daemons will additionally call reopen_logs() explicitly in their
startup code after config is loaded, eg

	setup_logging(getprogname(), DEBUG_FILE);
	...
	lpcfg_load(lp_ctx, config_file);
	...
	reopen_logs();

By calling reopen_logs_internal() implicitly from debug_set_logfile() there's no
need to call reopen_logs() explicitly anymore to apply the logfile.

As reopen_logs() will also apply other logging configuration options, we have to
keep the explicit calls in the daemon code. But at least this allows consistent
logging setup wrt to the logfile in the new cmdline library.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897

Signed-off-by: Ralph Boehme &lt;slow@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This simplifies the logging API for callers that typically would want to set
logging by just setup_logging() once without bothering that typically
configuration is loaded (via some lpcfg_load*() or lp_load*() varient) which
will only then pick up the configured logfile from smb.conf without actually
applying the new logifle to the logging subsytem.

Therefor our daemons will additionally call reopen_logs() explicitly in their
startup code after config is loaded, eg

	setup_logging(getprogname(), DEBUG_FILE);
	...
	lpcfg_load(lp_ctx, config_file);
	...
	reopen_logs();

By calling reopen_logs_internal() implicitly from debug_set_logfile() there's no
need to call reopen_logs() explicitly anymore to apply the logfile.

As reopen_logs() will also apply other logging configuration options, we have to
keep the explicit calls in the daemon code. But at least this allows consistent
logging setup wrt to the logfile in the new cmdline library.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897

Signed-off-by: Ralph Boehme &lt;slow@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>lib/debug: fix fd check before dup'ing to stderr</title>
<updated>2021-11-11T13:49:32+00:00</updated>
<author>
<name>Ralph Boehme</name>
<email>slow@samba.org</email>
</author>
<published>2021-11-10T13:13:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=948a82bd2651e73e4e669a89dc77ba93abbb9b2f'/>
<id>948a82bd2651e73e4e669a89dc77ba93abbb9b2f</id>
<content type='text'>
Before I added per-class logfile and we had only one fd for the logfile the code
looked like this:

        /* Take over stderr to catch output into logs */
        if (state.fd &gt; 0) {
                if (dup2(state.fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much
                           that can be done on such a fundamental
                           failure... */
                        close_low_fd(2);
                }
        }

In the current code the equivalent to state.fd is dbgc_config[DBGC_ALL].fd.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897

Signed-off-by: Ralph Boehme &lt;slow@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before I added per-class logfile and we had only one fd for the logfile the code
looked like this:

        /* Take over stderr to catch output into logs */
        if (state.fd &gt; 0) {
                if (dup2(state.fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much
                           that can be done on such a fundamental
                           failure... */
                        close_low_fd(2);
                }
        }

In the current code the equivalent to state.fd is dbgc_config[DBGC_ALL].fd.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897

Signed-off-by: Ralph Boehme &lt;slow@samba.org&gt;
Reviewed-by: Andreas Schneider &lt;asn@samba.org&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>debug: Add debug_syslog_format setting</title>
<updated>2021-11-01T06:37:32+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2021-10-28T08:05:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=5e1e9d74ab6f59a62ac8dae3239299a0ef334708'/>
<id>5e1e9d74ab6f59a62ac8dae3239299a0ef334708</id>
<content type='text'>
Without debug_hires_timestamp this produces a syslog style header
containing:

  "MON DD HH:MM:SS HOSTNAME PROGNAME[PID] "

With debug_hires_timestamp this produces a syslog style header
containing:

  "RFC5424-TIMESTAMP HOSTNAME PROGNAME[PID] "

All other settings are ignored.

This will be made visible via smb.conf in a subsequent commit.

This commit adds some simple hostname handling.  It avoids using
get_myname() from util.c because using that potentially pulls in all
manner of dependencies.  No real error handling is done.  In the worst
case debug_set_hostname() sets the hostname to a truncated version of
the given string.  Similarly, in an even weirder world,
ensure_hostname() sets the hostname to a truncation of "unknown".
Both of these are unlikely in all reasonable cases.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Ralph Boehme &lt;slow@samba.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Without debug_hires_timestamp this produces a syslog style header
containing:

  "MON DD HH:MM:SS HOSTNAME PROGNAME[PID] "

With debug_hires_timestamp this produces a syslog style header
containing:

  "RFC5424-TIMESTAMP HOSTNAME PROGNAME[PID] "

All other settings are ignored.

This will be made visible via smb.conf in a subsequent commit.

This commit adds some simple hostname handling.  It avoids using
get_myname() from util.c because using that potentially pulls in all
manner of dependencies.  No real error handling is done.  In the worst
case debug_set_hostname() sets the hostname to a truncated version of
the given string.  Similarly, in an even weirder world,
ensure_hostname() sets the hostname to a truncation of "unknown".
Both of these are unlikely in all reasonable cases.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Ralph Boehme &lt;slow@samba.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>debug: Optimise construction of msg_no_nl</title>
<updated>2021-10-14T11:10:40+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2021-10-14T00:08:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=a9a3555b43075c46e2051e6c1ef80762a0a19120'/>
<id>a9a3555b43075c46e2051e6c1ef80762a0a19120</id>
<content type='text'>
If it isn't used then it isn't copied.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;

Autobuild-User(master): Volker Lendecke &lt;vl@samba.org&gt;
Autobuild-Date(master): Thu Oct 14 11:10:40 UTC 2021 on sn-devel-184
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If it isn't used then it isn't copied.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;

Autobuild-User(master): Volker Lendecke &lt;vl@samba.org&gt;
Autobuild-Date(master): Thu Oct 14 11:10:40 UTC 2021 on sn-devel-184
</pre>
</div>
</content>
</entry>
<entry>
<title>debug: Move msg_no_nl to state</title>
<updated>2021-10-14T10:21:30+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2021-10-14T00:00:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=62fd771aea4bfb9f3042c80207e9800b74a43f75'/>
<id>62fd771aea4bfb9f3042c80207e9800b74a43f75</id>
<content type='text'>
This enables an optimisation.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This enables an optimisation.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>debug: Optimise early return when header string buffer is full</title>
<updated>2021-10-14T10:21:30+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2021-10-13T09:40:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=cb70eea0536a33583cd57e8dd416bfc2e37fe9d2'/>
<id>cb70eea0536a33583cd57e8dd416bfc2e37fe9d2</id>
<content type='text'>
The existing check is for truncation, not whether the buffer is full.
However, if the buffer is full (i.e. hs_len == sizeof(header_str) - 1)
then there's no use trying subsequent snprintf() calls because there
will be one byte available that already contains the NUL-terminator.
A subsequent call will just do a no-op truncation.

Check for full buffer instead.

This might be confusing because it isn't the standard check that is
done after snprintf() calls.  Is it worth it for a rare corner case?

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The existing check is for truncation, not whether the buffer is full.
However, if the buffer is full (i.e. hs_len == sizeof(header_str) - 1)
then there's no use trying subsequent snprintf() calls because there
will be one byte available that already contains the NUL-terminator.
A subsequent call will just do a no-op truncation.

Check for full buffer instead.

This might be confusing because it isn't the standard check that is
done after snprintf() calls.  Is it worth it for a rare corner case?

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>debug: Optimise to avoid walking the header string</title>
<updated>2021-10-14T10:21:30+00:00</updated>
<author>
<name>Martin Schwenke</name>
<email>martin@meltin.net</email>
</author>
<published>2021-10-13T01:06:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/samba.git/commit/?id=c5061ebe2146b6e8257205a4ad9ba69d1caa4c7d'/>
<id>c5061ebe2146b6e8257205a4ad9ba69d1caa4c7d</id>
<content type='text'>
strlcat() needs to walk to the end of its first argument.  However,
but the length of state.header_str is already known, so optimise by
manually appending the extra characters if they will fit.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
strlcat() needs to walk to the end of its first argument.  However,
but the length of state.header_str is already known, so optimise by
manually appending the extra characters if they will fit.

Signed-off-by: Martin Schwenke &lt;martin@meltin.net&gt;
Reviewed-by: Volker Lendecke &lt;vl@samba.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
