restore(8) fd leak fix
Hi All, From NetBSD: Fix fd leak. Found by cppcheck Index: src/sbin/restore/symtab.c === RCS file: /cvs/src/sbin/restore/symtab.c,v retrieving revision 1.20 diff -u -p -r1.20 symtab.c --- src/sbin/restore/symtab.c 24 Apr 2013 13:46:29 - 1.20 +++ src/sbin/restore/symtab.c 29 Dec 2013 11:37:28 - @@ -553,6 +553,7 @@ initsymtable(char *filename) warn(read); panic(cannot read symbol table file %s\n, filename); } + (void)close(fd); switch (command) { case 'r': /*
ldconfig fd leak fix
Hi All, From NetBSD: Fix file descriptor leak. Found by cppcheck. Index: src/libexec/ld.so/ldconfig/ldconfig.c === RCS file: /cvs/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -r1.31 ldconfig.c --- src/libexec/ld.so/ldconfig/ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ src/libexec/ld.so/ldconfig/ldconfig.c 29 Dec 2013 11:53:38 - @@ -416,16 +416,16 @@ buildhints(void) if (write(fd, hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, strtab, strtab_sz) != strtab_sz) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (close(fd) != 0) { warn(%s, _PATH_LD_HINTS); @@ -438,6 +438,8 @@ buildhints(void) } ret = 0; +fdout: + (void)close(fd); out: free(blist); free(strtab);
lpr fd leak fix
Hi All, From NetBSD: Fix fd leak in error cases. Found by cppcheck. Index: cmds.c === RCS file: /cvs/src/usr.sbin/lpr/lpc/cmds.c,v Index: cmds.c === RCS file: /cvs/src/usr.sbin/lpr/lpc/cmds.c,v retrieving revision 1.25 diff -u -p -r1.25 cmds.c --- cmds.c 24 Nov 2013 21:32:32 - 1.25 +++ cmds.c 29 Dec 2013 12:12:49 - @@ -594,6 +594,8 @@ putmsg(int argc, char **argv) if (fd 0 || flock(fd, LOCK_EX) 0) { printf(\tcannot create status file\n); PRIV_END; + if (fd = 0) + (void)close(fd); return; } PRIV_END;
Re: lpr fd leak fix
Diff got garbled. Re-sending it: Index: cmds.c === RCS file: /cvs/src/usr.sbin/lpr/lpc/cmds.c,v retrieving revision 1.25 diff -u -p -r1.25 cmds.c --- cmds.c 24 Nov 2013 21:32:32 - 1.25 +++ cmds.c 29 Dec 2013 12:12:49 - @@ -594,6 +594,8 @@ putmsg(int argc, char **argv) if (fd 0 || flock(fd, LOCK_EX) 0) { printf(\tcannot create status file\n); PRIV_END; + if (fd = 0) + (void)close(fd); return; } PRIV_END;
Re: ldconfig fd leak fix
Hi, Accidentally deleted this message from my inbox. This is a reconstruction from mailing list archive. Suggestion/comment below. Earlier today: Hi All, From NetBSD: Fix file descriptor leak. Found by cppcheck. Index: src/libexec/ld.so/ldconfig/ldconfig.c === RCS file: /cvs/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -r1.31 ldconfig.c --- src/libexec/ld.so/ldconfig/ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ src/libexec/ld.so/ldconfig/ldconfig.c 29 Dec 2013 11:53:38 - @@ -416,16 +416,16 @@ buildhints(void) if (write(fd, hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, strtab, strtab_sz) != strtab_sz) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (close(fd) != 0) { warn(%s, _PATH_LD_HINTS); @@ -438,6 +438,8 @@ buildhints(void) } ret = 0; +fdout: + (void)close(fd); out: free(blist); free(strtab); Why not a simpler diff where the the close() call is moved after 'out:' label instead of introducing a new label and an additional close() call? Like such: (disclaimer: not tested, not even compiled.) Index: ldconfig.c === RCS file: /cvs/obsd/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -u -p -r1.31 ldconfig.c --- ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ ldconfig.c 29 Dec 2013 15:31:58 - @@ -322,7 +322,7 @@ hinthash(char *cp, int vmajor, int vmino int buildhints(void) { - int strtab_sz = 0, nhints = 0, fd, i, ret = -1, str_index = 0; + int strtab_sz = 0, nhints = 0, fd = -1, i, ret = -1, str_index = 0; struct hints_bucket *blist; struct hints_header hdr; struct shlib_list *shp; @@ -427,10 +427,6 @@ buildhints(void) warn(%s, _PATH_LD_HINTS); goto out; } - if (close(fd) != 0) { - warn(%s, _PATH_LD_HINTS); - goto out; - } if (rename(tmpfilenam, _PATH_LD_HINTS) != 0) { warn(%s, _PATH_LD_HINTS); @@ -439,6 +435,8 @@ buildhints(void) ret = 0; out: + if (-1 != fd close(fd) != 0) + warn(%s, _PATH_LD_HINTS); free(blist); free(strtab); return (ret);
Re: ldconfig fd leak fix
On Sun, Dec 29, 2013 at 09:51:28AM -0800, patrick keshishian wrote: Hi, Accidentally deleted this message from my inbox. This is a reconstruction from mailing list archive. Suggestion/comment below. Earlier today: Hi All, From NetBSD: Fix file descriptor leak. Found by cppcheck. Index: src/libexec/ld.so/ldconfig/ldconfig.c === RCS file: /cvs/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -r1.31 ldconfig.c --- src/libexec/ld.so/ldconfig/ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ src/libexec/ld.so/ldconfig/ldconfig.c 29 Dec 2013 11:53:38 - @@ -416,16 +416,16 @@ buildhints(void) if (write(fd, hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, strtab, strtab_sz) != strtab_sz) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (close(fd) != 0) { warn(%s, _PATH_LD_HINTS); @@ -438,6 +438,8 @@ buildhints(void) } ret = 0; +fdout: + (void)close(fd); out: free(blist); free(strtab); Why not a simpler diff where the the close() call is moved after 'out:' label instead of introducing a new label and an additional close() call? That's equally possible. I adapted the diff from the NetBSD fix, which uses the additional label. I guess that it will boil down to the ldconfig maintainer to decide which way is better :-) Like such: (disclaimer: not tested, not even compiled.) Index: ldconfig.c === RCS file: /cvs/obsd/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -u -p -r1.31 ldconfig.c --- ldconfig.c13 Nov 2013 05:41:42 - 1.31 +++ ldconfig.c29 Dec 2013 15:31:58 - @@ -322,7 +322,7 @@ hinthash(char *cp, int vmajor, int vmino int buildhints(void) { - int strtab_sz = 0, nhints = 0, fd, i, ret = -1, str_index = 0; + int strtab_sz = 0, nhints = 0, fd = -1, i, ret = -1, str_index = 0; struct hints_bucket *blist; struct hints_header hdr; struct shlib_list *shp; @@ -427,10 +427,6 @@ buildhints(void) warn(%s, _PATH_LD_HINTS); goto out; } - if (close(fd) != 0) { - warn(%s, _PATH_LD_HINTS); - goto out; - } if (rename(tmpfilenam, _PATH_LD_HINTS) != 0) { warn(%s, _PATH_LD_HINTS); @@ -439,6 +435,8 @@ buildhints(void) ret = 0; out: + if (-1 != fd close(fd) != 0) + warn(%s, _PATH_LD_HINTS); free(blist); free(strtab); return (ret);
user(8) fd fix
Hi All, From NetBSD: Close masterfd after reading from it. Found by cppcheck. Index: src/usr.sbin/user/user.c === RCS file: /cvs/src/usr.sbin/user/user.c,v retrieving revision 1.98 diff -u -p -r1.98 user.c --- src/usr.sbin/user/user.c23 Nov 2013 17:14:05 - 1.98 +++ src/usr.sbin/user/user.c29 Dec 2013 19:55:36 - @@ -1014,6 +1014,7 @@ adduser(char *login_name, user_t *up) pw_abort(); err(EXIT_FAILURE, read error on %s, _PATH_MASTERPASSWD); } + (void)close(masterfd); /* if no uid was specified, get next one in [low_uid..high_uid] range */ sync_uid_gid = (strcmp(up-u_primgrp, =uid) == 0); if (up-u_uid == UID_MAX) {
pwd_mkdb fd leak fix
Hi All, From NetBSD: fd leak fix, found by cppcheck. Index: src/usr.sbin/pwd_mkdb/pwd_mkdb.c === RCS file: /cvs/src/usr.sbin/pwd_mkdb/pwd_mkdb.c,v retrieving revision 1.43 diff -u -p -r1.43 pwd_mkdb.c --- src/usr.sbin/pwd_mkdb/pwd_mkdb.c8 Jan 2010 13:29:08 - 1.43 +++ src/usr.sbin/pwd_mkdb/pwd_mkdb.c29 Dec 2013 20:11:34 - @@ -375,8 +375,10 @@ cp(char *from, char *to, mode_t mode) if ((from_fd = open(from, O_RDONLY, 0)) 0) error(from); - if ((to_fd = open(to, O_WRONLY|O_CREAT|O_EXCL, mode)) 0) + if ((to_fd = open(to, O_WRONLY|O_CREAT|O_EXCL, mode)) 0) { + (void)close(from_fd); error(to); + } while ((rcount = read(from_fd, buf, MAXBSIZE)) 0) { wcount = write(to_fd, buf, rcount); if (rcount != wcount || wcount == -1) {
Re: user(8) fd fix
On Sun, Dec 29, 2013 at 11:59, Loganaden Velvindron wrote: Hi All, From NetBSD: Close masterfd after reading from it. Found by cppcheck. This is wrong. Proper code using fdopen() with error checking should close(2) fildes in case of failure, and fclose(3) the resulting FILE * in case of success. Index: src/usr.sbin/user/user.c === RCS file: /cvs/src/usr.sbin/user/user.c,v retrieving revision 1.98 diff -u -p -r1.98 user.c --- src/usr.sbin/user/user.c 23 Nov 2013 17:14:05 - 1.98 +++ src/usr.sbin/user/user.c 29 Dec 2013 19:55:36 - @@ -1014,6 +1014,7 @@ adduser(char *login_name, user_t *up) pw_abort(); err(EXIT_FAILURE, read error on %s, _PATH_MASTERPASSWD); } + (void)close(masterfd); /* if no uid was specified, get next one in [low_uid..high_uid] range */ sync_uid_gid = (strcmp(up-u_primgrp, =uid) == 0); if (up-u_uid == UID_MAX) {
Re: user(8) fd fix
On Sun, Dec 29, 2013 at 03:19:08PM -0500, Ted Unangst wrote: On Sun, Dec 29, 2013 at 11:59, Loganaden Velvindron wrote: Hi All, From NetBSD: Close masterfd after reading from it. Found by cppcheck. This is wrong. Proper code using fdopen() with error checking should close(2) fildes in case of failure, and fclose(3) the resulting FILE * in case of success. You're right ! I just checked the man page. Index: src/usr.sbin/user/user.c === RCS file: /cvs/src/usr.sbin/user/user.c,v retrieving revision 1.98 diff -u -p -r1.98 user.c --- src/usr.sbin/user/user.c23 Nov 2013 17:14:05 - 1.98 +++ src/usr.sbin/user/user.c29 Dec 2013 19:55:36 - @@ -1014,6 +1014,7 @@ adduser(char *login_name, user_t *up) pw_abort(); err(EXIT_FAILURE, read error on %s, _PATH_MASTERPASSWD); } + (void)close(masterfd); /* if no uid was specified, get next one in [low_uid..high_uid] range */ sync_uid_gid = (strcmp(up-u_primgrp, =uid) == 0); if (up-u_uid == UID_MAX) {
Re: ldconfig fd leak fix
On Sun, Dec 29, 2013 at 11:49:29AM -0800, Loganaden Velvindron wrote: On Sun, Dec 29, 2013 at 09:51:28AM -0800, patrick keshishian wrote: Hi, Accidentally deleted this message from my inbox. This is a reconstruction from mailing list archive. Suggestion/comment below. Earlier today: Hi All, From NetBSD: Fix file descriptor leak. Found by cppcheck. Index: src/libexec/ld.so/ldconfig/ldconfig.c === RCS file: /cvs/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -r1.31 ldconfig.c --- src/libexec/ld.so/ldconfig/ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ src/libexec/ld.so/ldconfig/ldconfig.c 29 Dec 2013 11:53:38 - @@ -416,16 +416,16 @@ buildhints(void) if (write(fd, hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (write(fd, strtab, strtab_sz) != strtab_sz) { warn(%s, _PATH_LD_HINTS); - goto out; + goto fdout; } if (close(fd) != 0) { warn(%s, _PATH_LD_HINTS); @@ -438,6 +438,8 @@ buildhints(void) } ret = 0; +fdout: + (void)close(fd); out: free(blist); free(strtab); Why not a simpler diff where the the close() call is moved after 'out:' label instead of introducing a new label and an additional close() call? That's equally possible. I adapted the diff from the NetBSD fix, which uses the additional label. I guess that it will boil down to the ldconfig maintainer to decide which way is better :-) My comment about additional close() call is not entirely explicit. With the original suggested patch, if the code reaches the 'ret = 0;' assignment, close(fd) gets called again, and at this point fd is already closed. Cheers, --patrick Like such: (disclaimer: not tested, not even compiled.) Index: ldconfig.c === RCS file: /cvs/obsd/src/libexec/ld.so/ldconfig/ldconfig.c,v retrieving revision 1.31 diff -u -p -u -p -r1.31 ldconfig.c --- ldconfig.c 13 Nov 2013 05:41:42 - 1.31 +++ ldconfig.c 29 Dec 2013 15:31:58 - @@ -322,7 +322,7 @@ hinthash(char *cp, int vmajor, int vmino int buildhints(void) { - int strtab_sz = 0, nhints = 0, fd, i, ret = -1, str_index = 0; + int strtab_sz = 0, nhints = 0, fd = -1, i, ret = -1, str_index = 0; struct hints_bucket *blist; struct hints_header hdr; struct shlib_list *shp; @@ -427,10 +427,6 @@ buildhints(void) warn(%s, _PATH_LD_HINTS); goto out; } - if (close(fd) != 0) { - warn(%s, _PATH_LD_HINTS); - goto out; - } if (rename(tmpfilenam, _PATH_LD_HINTS) != 0) { warn(%s, _PATH_LD_HINTS); @@ -439,6 +435,8 @@ buildhints(void) ret = 0; out: + if (-1 != fd close(fd) != 0) + warn(%s, _PATH_LD_HINTS); free(blist); free(strtab); return (ret);
Re: OpenBSD base doesn't build on ARMv7
On Wed, Dec 25, 2013 at 10:56:59PM -0500, Nick Holland wrote: On 12/25/13 19:08, Juan Francisco Cantero Hurtado wrote: Hi, I've been seeing the same error for weeks: === gnu/usr.bin/cc/libgcc Using undefined dynamic variable $* (line 0 of (null)) Using undefined dynamic variable $* (line 0 of (null)) /usr/src/gnu/usr.bin/cc/libgcc/obj/../cc/cc -B /usr/src/gnu/usr.bin/cc/libgcc/obj/../cc1 -O2 -pipe -g -DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -DHAVE_GTHR_DEFAULT -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc -I. -I/usr/src/gnu/usr.bin/cc/libgcc/../cc_tools -Dinhibit_libc -fno-inline -DIN_GCC -DHAVE_CONFIG_H -DPREFIX=/usr -I/usr/src/gnu/usr.bin/cc/libgcc/obj/../cc_tools -I/usr/src/gnu/usr.bin/cc/libgcc/../cc_tools -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/libcpp/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/libdecnumber-c /usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config/floatunsidf.c -o floatunsidf.o /usr/src/gnu/usr.bin/cc/libgcc/obj/../cc/cc -B /usr/src/gnu/usr.bin/cc/libgcc/obj/../cc1 -O2 -pipe -g -DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -DHAVE_GTHR_DEFAULT -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc -I. -I/usr/src/gnu/usr.bin/cc/libgcc/../cc_tools -Dinhibit_libc -fno-inline -DIN_GCC -DHAVE_CONFIG_H -DPREFIX=/usr -I/usr/src/gnu/usr.bin/cc/libgcc/obj/../cc_tools -I/usr/src/gnu/usr.bin/cc/libgcc/../cc_tools -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/libcpp/include -I/usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/libdecnumber-c /usr/src/gnu/usr.bin/cc/libgcc/../../../gcc/gcc/config/floatunsisf.c -o floatunsisf.o make: don't know how to make .vis (prerequisite of: _bb_init_func.o _dvmd_tls.o) Stop in gnu/usr.bin/cc/libgcc *** Error 2 in gnu/usr.bin/cc (bsd.subdir.mk:48 'all') *** Error 2 in gnu/usr.bin (bsd.subdir.mk:48 'all') *** Error 2 in gnu (bsd.subdir.mk:48 'all') *** Error 2 in . (bsd.subdir.mk:48 'all') *** Error 2 in /usr/src (Makefile:89 'build') Any idea? The full log is here (ignore the messages in spanish, I use a script to compile the base): http://juanfra.info/bl/openbsd-arm-201312/error_base.log I just spun a build without issues a couple days ago. I did have an issue with making a release, but certainly not what you are seeing above. (and I haven't looked closely at my release error messages yet) maybe check your gnu/usr.bin/cc directory for 'M's and 'C's when doing a checkout against another source? Nick I deleted the src dir and downloaded again the code from two anoncvs servers. The build fails always at the same point. Maybe my system is broken, I don't know. Glad to hear you can build a snapshot :P -- Juan Francisco Cantero Hurtado http://juanfra.info
column memory leak fix
Hi All, From NetBSD: Plug memory leak. Coverity CID 1596 Index: src/usr.bin/column/column.c === RCS file: /cvs/src/usr.bin/column/column.c,v retrieving revision 1.16 diff -u -p -r1.16 column.c --- src/usr.bin/column/column.c 26 Nov 2013 13:18:55 - 1.16 +++ src/usr.bin/column/column.c 30 Dec 2013 06:38:02 - @@ -241,6 +241,9 @@ maketbl(void) (void)printf(%s\n, t-list[coloff]); } } + free(tbl); + free(cols); + free(lens); } #defineDEFNUM 1000
cmp fd leak fix
Hi All, From NetBSD: Plug fd leak. Coverity CID 1624. Index: src/usr.bin/cmp/special.c === RCS file: /cvs/src/usr.bin/cmp/special.c,v retrieving revision 1.7 diff -u -p -r1.7 special.c --- src/usr.bin/cmp/special.c 19 Jan 2011 13:01:25 - 1.7 +++ src/usr.bin/cmp/special.c 30 Dec 2013 06:54:05 - @@ -88,6 +88,8 @@ eof: if (ferror(fp1)) } else if (feof(fp2)) eofmsg(file2); + (void)fclose(fp1); + (void)fclose(fp2); if (dfound) exit(DIFF_EXIT); }