On Thu, 15 Dec 2016, Eduard Rozenberg wrote:
>
> In case it?s useful, here are several warnings that were generated
> on my Linux compile on Slackware 14.1 kernel 3.10.17.
>
>
> pw_dup.c: In function 'pw_dup':
> pw_dup.c:47:3: warning: 'ssize' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
> (void)memcpy(cp, pw->name, size); \
> ^
> pw_dup.c:57:39: note: 'ssize' was declared here
> size_t nsize, psize, gsize, dsize, ssize, total;
> ^
> pw_dup.c:47:3: warning: 'dsize' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
> (void)memcpy(cp, pw->name, size); \
> ^
> pw_dup.c:57:32: note: 'dsize' was declared here
> size_t nsize, psize, gsize, dsize, ssize, total;
> ^
> pw_dup.c:47:3: warning: 'gsize' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
> (void)memcpy(cp, pw->name, size); \
> ^
> pw_dup.c:57:25: note: 'gsize' was declared here
> size_t nsize, psize, gsize, dsize, ssize, total;
> ^
> pw_dup.c:47:3: warning: 'psize' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
> (void)memcpy(cp, pw->name, size); \
> ^
> pw_dup.c:57:18: note: 'psize' was declared here
> size_t nsize, psize, gsize, dsize, ssize, total;
> ^
> pw_dup.c:49:6: warning: 'nsize' may be used uninitialized in this function
> [-Wmaybe-uninitialized]
> cp += size; \
> ^
> pw_dup.c:57:11: note: 'nsize' was declared here
> size_t nsize, psize, gsize, dsize, ssize, total;
> ^
>
> gcc -DHAVE_CONFIG_H -I. -I../.. -I../../smtpd -I../../openbsd-compat -I.
> -I/usr/include -DSMTPD_CONFDIR=\"/etc/opensmtpd\"
> -DPATH_CHROOT=\"/var/empty\" -DPATH_SMTPCTL=\"/usr/sbin/smtpctl\"
> -DPATH_MAILLOCAL=\"/usr/libexec/opensmtpd/mail.local\"
> -DPATH_LIBEXEC=\"/usr/libexec/opensmtpd\" -DHAVE_CONFIG_H -DIO_SSL
> -DCA_FILE=\"/etc/ssl/certs/ca-certificates.crt\" -O2 -fPIC -fstack-protector
> -fPIC -DPIC -Wall -Wpointer-arith -Wuninitialized -Wsign-compare
> -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign
> -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset -D_BSD_SOURCE
> -D_GNU_SOURCE -DNEED_EVENT_ASR_RUN -c -o ../../smtpd/smtpd-to.o `test -f
> '../../smtpd/to.c' || echo './'`../../smtpd/to.c
> ../../smtpd/to.c: In function 'time_to_text':
> ../../smtpd/to.c:212:5: warning: assignment discards 'const' qualifier from
> pointer target type [enabled by default]
> tz = lt->tm_zone;
> ^
>
> gcc -DHAVE_CONFIG_H -I. -I../.. -I../../smtpd -I../../openbsd-compat -I.
> -I/usr/include -DSMTPD_CONFDIR=\"/etc/opensmtpd\"
> -DPATH_CHROOT=\"/var/empty\" -DPATH_SMTPCTL=\"/usr/sbin/smtpctl\"
> -DPATH_MAILLOCAL=\"/usr/libexec/opensmtpd/mail.local\"
> -DPATH_LIBEXEC=\"/usr/libexec/opensmtpd\" -DHAVE_CONFIG_H -DNO_IO
> -DPATH_GZCAT=\"/usr/bin/zcat\"
> -DPATH_ENCRYPT=\"/usr/libexec/opensmtpd/encrypt\" -O2 -fPIC -fstack-protector
> -fPIC -DPIC -Wall -Wpointer-arith -Wuninitialized -Wsign-compare
> -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign
> -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset -D_BSD_SOURCE
> -D_GNU_SOURCE -c -o ../../smtpd/smtpctl-parser.o `test -f
> '../../smtpd/parser.c' || echo './'`../../smtpd/parser.c
> ../../smtpd/parser.c:123:1: warning: 'cmd_dump' defined but not used
> [-Wunused-function]
> cmd_dump(struct node *node, int depth)
> ^
>
> gcc -DHAVE_CONFIG_H -I. -I../.. -I../../smtpd -I../../openbsd-compat -I.
> -I/usr/include -DSMTPD_CONFDIR=\"/etc/opensmtpd\"
> -DPATH_CHROOT=\"/var/empty\" -DPATH_SMTPCTL=\"/usr/sbin/smtpctl\"
> -DPATH_MAILLOCAL=\"/usr/libexec/opensmtpd/mail.local\"
> -DPATH_LIBEXEC=\"/usr/libexec/opensmtpd\" -DHAVE_CONFIG_H -DNO_IO
> -DPATH_GZCAT=\"/usr/bin/zcat\"
> -DPATH_ENCRYPT=\"/usr/libexec/opensmtpd/encrypt\" -O2 -fPIC -fstack-protector
> -fPIC -DPIC -Wall -Wpointer-arith -Wuninitialized -Wsign-compare
> -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign
> -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset -D_BSD_SOURCE
> -D_GNU_SOURCE -c -o ../../smtpd/smtpctl-to.o `test -f '../../smtpd/to.c' ||
> echo './'`../../smtpd/to.c
> ../../smtpd/to.c: In function 'time_to_text':
> ../../smtpd/to.c:212:5: warning: assignment discards 'const' qualifier from
> pointer target type [enabled by default]
> tz = lt->tm_zone;
> ^
>
The first warnings for pw_dup.c occur because the compiler does not figure
out that the size variables are initialized by use of the PW_SIZE macro.
Nonetheless it is good form to initialize variables during declaration.
Here is a patch that would eliminate the warning messages for pw_dup.c:
--- openbsd-compat/pw_dup.c.orig 2016-10-12 00:16:24.000000000 -0700
+++ openbsd-compat/pw_dup.c 2016-12-16 10:49:24.673822372 -0800
@@ -53,12 +53,13 @@
struct passwd *
pw_dup(const struct passwd *pw)
{
- char *cp;
- size_t nsize, psize, gsize, dsize, ssize, total;
+ char *cp = NULL;
+ size_t nsize = 0, psize = 0, gsize = 0, dsize = 0;
+ size_t ssize = 0, total = 0;
#if HAVE_STRUCT_PASSWD_PW_CLASS
- size_t csize;
+ size_t csize = 0;
#endif
- struct passwd *newpw;
+ struct passwd *newpw = NULL;
/* Allocate in one big chunk for easy freeing */
total = sizeof(struct passwd);
--------------------------------------------------------
-Richard Narron
--
You received this mail because you are subscribed to [email protected]
To unsubscribe, send a mail to: [email protected]