mg(1) does not close DIR on error path

2012-03-24 Thread Igor Zinovik
Hello.

mg(1) editor has a small resource leak in make_file_list() function.
If it cannot allocate space for `current' list it returns without
closing `dirp' with closedir() call.

Index: fileio.c
===
RCS file: /cvs/src/usr.bin/mg/fileio.c,v
retrieving revision 1.84
diff -U 3 -p -r1.84 fileio.c
--- fileio.c21 Jan 2011 19:10:13 -  1.84
+++ fileio.c18 Mar 2011 19:55:18 -
@@ -551,6 +551,7 @@ make_file_list(char *buf)
 
if ((current = malloc(sizeof(struct list))) == NULL) {
free_file_list(last);
+   closedir(dirp);
return (NULL);
}
ret = snprintf(fl_name, sizeof(fl_name),



Re: ral(4) diff

2011-03-12 Thread Igor Zinovik
On Mar 10, Tim van der Molen wrote: 
 I have the following ral(4):
 
 ral0 at pci0 dev 13 function 0 Ralink RT2561S rev 0x00: irq 5, address 
 00:1d:7d:49:28:92
 ral0: MAC/BBP RT2561C, RF RT2527
 
 After a commit from August 2010 (see
 http://marc.info/?l=openbsd-cvsm=128095139804862) the ral stopped
 working: clients could not associate with it in hostap mode and it could
 not detect other APs with ifconfig scan.
 
 After a hint from damien@ I came up with the following diff which brings
 back some of the code that was removed by the commit mentioned above.
 
 damien@ suggested I post the diff here. If you have an RT2561 or RT2661,
 please test it.

My ral(4) was running fine without this diff.  After i applied it
nothing changed, it is working normally.  Clients still can connect to my AP.

ral0 at pci2 dev 10 function 0 Ralink RT2561S rev 0x00: irq 11, address 
00:11:6b:35:03:d5
ral0: MAC/BBP RT2661B, RF RT2527




[patch] file descriptor leak fix

2010-03-21 Thread Igor Zinovik

Hello, tech@

Following diff fixes file descriptor leak `ifd'.

Index: diffreg.c
===
RCS file: /cvs/src/usr.bin/diff/diffreg.c,v
retrieving revision 1.73
diff -u -r1.73 diffreg.c
--- diffreg.c   27 Oct 2009 23:59:37 -  1.73
+++ diffreg.c   21 Mar 2010 10:55:43 -
@@ -514,8 +514,10 @@
return (NULL);
}
 
-	if ((ofd = mkstemp(tempfile))  0)

+   if ((ofd = mkstemp(tempfile))  0) {
+   close(ifd);
return (NULL);
+   }
unlink(tempfile);
while ((nread = read(ifd, buf, BUFSIZ))  0) {
if (write(ofd, buf, nread) != nread) {



[patch] fixes for sendbug

2010-03-21 Thread Igor Zinovik

Hello, tech@


Following diff fixes memory and FILE handle leaks.  `acpidir' is allocated via
asprintf(3) and `ifp' is opened via popen(3), but not closed.

Index: sendbug.c
===
RCS file: /cvs/src/usr.bin/sendbug/sendbug.c,v
retrieving revision 1.63
diff -u -r1.63 sendbug.c
--- sendbug.c   26 Aug 2009 20:40:40 -  1.63
+++ sendbug.c   21 Mar 2010 11:39:36 -
@@ -600,7 +600,9 @@
}
pclose(ofp);
}
+   pclose(ifp);
free(cmd);
+   free(acpidir);
 }
 
 void




[patch] small sychronization between OpenCVS and OpenRCS code

2010-03-21 Thread Igor Zinovik

Hello, tech@

This diff synchronizes OpenCVS rcs parser code with OpenRCS.  It shrinks code 
by 3
lines, but does exactly the same thing.  It also removes `buf' which
becomes redundant for this function.

Instead of calling strlcpy(3) three times we can put a line in file with
fprintf(3).  Should be no functional change.

Index: rcs.c
===
RCS file: /cvs/src/usr.bin/cvs/rcs.c,v
retrieving revision 1.291
diff -u -p -r1.291 rcs.c
--- rcs.c   7 Jun 2009 08:39:13 -   1.291
+++ rcs.c   21 Mar 2010 20:23:43 -
@@ -366,7 +366,7 @@ void
 rcs_write(RCSFILE *rfp)
 {
FILE *fp;
-   char buf[1024], numbuf[CVS_REV_BUFSZ], *fn, tmpdir[MAXPATHLEN];
+   char   numbuf[CVS_REV_BUFSZ], *fn, tmpdir[MAXPATHLEN];
struct rcs_access *ap;
struct rcs_sym *symp;
struct rcs_branch *brp;
@@ -424,11 +424,7 @@ rcs_write(RCSFILE *rfp)
if (RCSNUM_ISBRANCH(symp-rs_num))
rcsnum_addmagic(symp-rs_num);
rcsnum_tostr(symp-rs_num, numbuf, sizeof(numbuf));
-   if (strlcpy(buf, symp-rs_name, sizeof(buf)) = sizeof(buf) ||
-   strlcat(buf, :, sizeof(buf)) = sizeof(buf) ||
-   strlcat(buf, numbuf, sizeof(buf)) = sizeof(buf))
-   fatal(rcs_write: string overflow);
-   fprintf(fp, \n\t%s, buf);
+   fprintf(fp, \n\t%s:%s, symp-rs_name, numbuf);
}
fprintf(fp, ;\n);



[patch] fix for file descriptor leak in lpd(8)

2010-03-21 Thread Igor Zinovik

Hello, tech@

Do not leak file descriptor `fd' on error path.

Index: printjob.c
===
RCS file: /cvs/src/usr.sbin/lpr/lpd/printjob.c,v
retrieving revision 1.45
diff -u -p -r1.45 printjob.c
--- printjob.c  27 Oct 2009 23:59:52 -  1.45
+++ printjob.c  21 Mar 2010 21:18:34 -
@@ -1627,8 +1627,10 @@ pstatus(const char *msg, ...)
ftruncate(fd, 0);
len = vsnprintf(buf, sizeof(buf), msg, ap);
va_end(ap);
-   if (len == -1)
+   if (len == -1) {
+   (void)close(fd);
return;
+   }
if (len = sizeof(buf))
len = sizeof(buf) - 1;
buf[len++] = '\n';  /* replace NUL with newline */



[patch] dhcpd memory leak on error path

2010-03-21 Thread Igor Zinovik

Hello, tech@

Follwoing diff plugs memory leak on error path in dhcpd.

Index: confpars.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/confpars.c,v
retrieving revision 1.18
diff -u -p -r1.18 confpars.c
--- confpars.c  2 Jan 2010 04:21:16 -   1.18
+++ confpars.c  21 Mar 2010 21:34:02 -
@@ -522,8 +522,10 @@ void parse_host_declaration(cfile, group
host-name = name;
host-group = clone_group(group, parse_host_declaration);
 
-	if (!parse_lbrace(cfile))

+   if (!parse_lbrace(cfile)) {
+   free(host);
return;
+   }
 
 	do {

token = peek_token(val, cfile);



[patch] memory leak in pfctl_parser

2010-03-20 Thread Igor Zinovik

Hello, tech@

Following diff fixes memory leak.  `debug' is allocated via asprintf(3) so we
need to free it with free(3).

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.263
diff -u -r1.263 pfctl_parser.c
--- pfctl_parser.c  18 Mar 2010 12:15:22 -  1.263
+++ pfctl_parser.c  20 Mar 2010 20:01:12 -
@@ -528,6 +528,7 @@
printf(%-44s, statline);
asprintf(debug, Debug: %s, loglevel_to_string(s-debug));
printf(%15s\n\n, debug);
+   free(debug);
 
 	if (opts  PF_OPT_VERBOSE) {

printf(Hostid:   0x%08x\n, ntohl(s-hostid));



Re: Automatic package mirror discovery implementation for pkg_add(1) tool

2010-02-10 Thread Igor Zinovik
08.01.2010 15:30, Bob Beck writes:
 2010/1/8 Bob Beck b...@ualberta.ca:
 And what I mean by that Is that I would be willing to put together a similar
 trick for this on ftp.openbsd.org as I did for the installer - if
 someone was willing
 to integrate it into the pkg_add tools.

Maybe it is not polite to answer to this old thread, but I've integrated
(somehow) AutoMirrorDiscovery functionality into pkg_add tool, just to
prove myself that i can do that without crashing pkg_add functionality.  It is
very clumsy right now, but it works for me (with some bugs of course).

This is how it works (currently there is no knob to shut it up):
(/tmp)[213]% sudo pkg_add -d
Pinging anga.funkfeuer.at...OK
Pinging carroll.cac.psu.edu...OK
Pinging filedump.se.rit.edu...OK
Pinging ftp-stud.fht-esslingen.de...OK
Pinging ftp.arcane-networks.fr...OK
Pinging ftp.aso.ee...no response
Pinging ftp.belnet.be...OK
Pinging ftp.bytemine.net...OK
Pinging ftp.ca.openbsd.org...no response
Pinging ftp.cc.uoc.gr...no response
Pinging ftp.chg.ru...OK
Pinging ftp.crans.org...OK
Pinging ftp.cs.pu.edu.tw...no response
Pinging ftp.cse.buffalo.edu...no response
Pinging ftp.das.ufsc.br...OK
Pinging ftp.df.lth.se...OK
Pinging ftp.dkuug.dk...no response
Use of uninitialized value $ret in numeric eq (==) at
/usr/libdata/perl5/OpenBSD/AutoMirrorDiscovery.pm line 58.
Pinging ftp.duth.gr...no response
Pinging ftp.esat.net...OK
Pinging ftp.estpak.ee...OK
Pinging ftp.eu.openbsd.org...OK
Pinging ftp.fmed.uc.pt...no response
Pinging ftp.fr.openbsd.org...OK
Pinging ftp.freebsdchina.org...OK
Pinging ftp.freenet.de...OK
Pinging ftp.fsn.hu...OK
Pinging ftp.gamma.ru...OK
Pinging ftp.heanet.ie...OK
Pinging ftp.iinet.net.au...OK
Pinging ftp.inet.no...OK
Pinging ftp.irisa.fr...OK
Pinging ftp.is.co.za...OK
Pinging ftp.jaist.ac.jp...OK
Pinging ftp.jyu.fi...OK
Pinging ftp.kaist.ac.kr...no response
Pinging ftp.kddlabs.co.jp...no response
Pinging ftp.lambdaserver.com...OK
Pinging ftp.mirrorservice.org...OK
Pinging ftp.netbsd.se...OK
Pinging ftp.nluug.nl...OK
Pinging ftp.obsd.si...OK
Pinging ftp.openbsd.dk...OK
Pinging ftp.openbsd.or.id...OK
Pinging ftp.openbsd.org.ar...no response
Pinging ftp.openbsd.org...OK
Pinging ftp.piotrkosoft.net...no response
Pinging ftp.plig.net...OK
Pinging ftp.rediris.es...OK
Pinging ftp.spline.de...OK
Pinging ftp.task.gda.pl...OK
Pinging ftp.tcc.edu.tw...OK
Pinging ftp.tpnet.pl...OK
Pinging ftp.tw.openbsd.org...OK
Pinging ftp.udc.es...no response
Pinging ftp.ulak.net.tr...OK
Pinging ftp.uninett.no...OK
Pinging ftp.wu-wien.ac.at...OK
Pinging ftp2.fr.openbsd.org...OK
Pinging ftp3.usa.openbsd.org...OK
Pinging ftp5.usa.openbsd.org...OK
Pinging gulus.usherbrooke.ca...no response
Pinging mirror.aarnet.edu.au...OK
Pinging mirror.cdmon.com...OK
Pinging mirror.corbina.net...OK
Pinging mirror.hostfuss.com...OK
Pinging mirror.iawnet.sandia.gov...no response
Pinging mirror.internode.on.net...OK
Pinging mirror.pacific.net.au...OK
Pinging mirror.planetunix.net...OK
Pinging mirror.public-internet.co.uk...no response
Pinging mirror.rit.edu...OK
Pinging mirror.roothell.org...OK
Pinging mirror.switch.ch...OK
Pinging mirrors.24-7-solutions.net...OK
Pinging mirrors.localhost.net.ar...no response
Pinging mirrors.nic.funet.fi...OK
Pinging mirrors.ucr.ac.cr...no response
Pinging obsd.cec.mtu.edu...OK
Pinging openbsd.arcticnetwork.ca...OK
Pinging openbsd.bsdforen.de...OK
Pinging openbsd.ftp.fu-berlin.de...no response
Pinging openbsd.mirror.frontiernet.net...OK
Pinging openbsd.mirrors.pair.com...OK
Pinging openbsd.mirrors.tds.net...OK
Pinging openbsd.noc.jgm.gov.ar...no response
(/tmp)[214]% cat /var/db/ftpmirror.cache
ftp://mirrors.nic.funet.fi/pub/OpenBSD/4.6/packages/i386/
ftp://ftp.gamma.ru/pub/OpenBSD/4.6/packages/i386/
ftp://ftp.eu.openbsd.org/pub/OpenBSD/4.6/packages/i386/
(/tmp)[228]% echo $PKG_PATH

(/tmp)[229]% sudo pkg_add -i fdm
No packages available in the PKG_PATH
fdm-1.6:tdb-1.0.6p0: ok (1 to go)
fdm-1.6: ok


Here is the code:

/usr/src/usr.sbin/pkg_add/OpenBSD/AutoMirrorDiscovery.pm
# ex:ts=8 sw=4:
# $OpenBSD$
#
# Copyright (c) 2009 Igor Zinovik zino...@petrsu.ru
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# functionality for automatic fastest ftp mirror discovery

use strict;
use warnings;

package OpenBSD::AutoMirrorDiscovery;

use OpenBSD::Paths;
use Net::Ping;
use Net::FTP;

sub

[patch] httpd/src/modules/ssl/ssl_util_table.c - fd leak

2010-01-20 Thread Igor Zinovik

Hello.

Looks like a file descriptor leak?

Index: ssl_util_table.c
===
RCS file: /OpenBSD/src/usr.sbin/httpd/src/modules/ssl/ssl_util_table.c,v
retrieving revision 1.6
diff -u -r1.6 ssl_util_table.c
--- ssl_util_table.c2 Dec 2004 19:42:47 -   1.6
+++ ssl_util_table.c20 Jan 2010 20:13:22 -
@@ -2401,6 +2401,7 @@
 if (table_p == NULL) {
 if (error_p != NULL)
 *error_p = TABLE_ERROR_ALLOC;
+   close(fd);
 return NULL;
 }
 
@@ -2409,6 +2410,7 @@

 if (infile == NULL) {
 if (error_p != NULL)
 *error_p = TABLE_ERROR_OPEN;
+   close(fd);
 return NULL;
 }
 
@@ -2420,6 +2422,7 @@

 free_f(table_p);
 else
 free(table_p);
+   close(fd);
 return NULL;
 }
 table_p-ta_file_size = 0;
@@ -2433,6 +2436,7 @@
 if (table_p-ta_magic != TABLE_MAGIC) {
 if (error_p != NULL)
 *error_p = TABLE_ERROR_PNT;
+   close(fd);
 return NULL;
 }
 
@@ -2442,6 +2446,7 @@

 if (error_p != NULL)
 *error_p = TABLE_ERROR_ALLOC;
 table_p-ta_free(table_p);
+   close(fd);
 return NULL;
 }
 
@@ -2451,6 +2456,7 @@

 *error_p = TABLE_ERROR_READ;
 table_p-ta_free(table_p-ta_buckets);
 table_p-ta_free(table_p);
+   close(fd);
 return NULL;
 }
 
@@ -2476,6 +2482,7 @@

 table_p-ta_free(entry_p);
 table_p-ta_free(table_p);
 /* the other table elements will not be freed */
+   close(fd);
 return NULL;
 }
 if (fread(entry, sizeof(struct table_shell_st), 1, infile) != 1) {
@@ -2486,6 +2493,7 @@
 table_p-ta_free(entry_p);
 table_p-ta_free(table_p);
 /* the other table elements will not be freed */
+   close(fd);
 return NULL;
 }
 
@@ -2498,6 +2506,7 @@

 table_p-ta_free(table_p-ta_buckets);
 table_p-ta_free(table_p);
 /* the other table elements will not be freed */
+   close(fd);
 return NULL;
 }
 entry_p-te_key_size = entry.te_key_size;
@@ -2517,6 +2526,7 @@
 table_p-ta_free(entry_p);
 table_p-ta_free(table_p);
 /* the other table elements will not be freed */
+   close(fd);
 return NULL;
 }



[patch] dhcpd/confpars.c tiny memory leak

2010-01-08 Thread Igor Zinovik
  Hello, t...@.

dhcpd forgets to free(3) host.

Index: usr.sbin/dhcpd/confpars.c
===
RCS file: /OpenBSD/src/usr.sbin/dhcpd/confpars.c,v
retrieving revision 1.18
diff -u -r1.18 confpars.c
--- usr.sbin/dhcpd/confpars.c   2 Jan 2010 04:21:16 -   1.18
+++ usr.sbin/dhcpd/confpars.c   8 Jan 2010 12:24:34 -
@@ -522,8 +522,10 @@
host-name = name;
host-group = clone_group(group, parse_host_declaration);

-   if (!parse_lbrace(cfile))
+   if (!parse_lbrace(cfile)) {
+   free(host);
return;
+   }

do {
token = peek_token(val, cfile);



[patch] lib/libc/yp/yp_all.c mem leak

2010-01-08 Thread Igor Zinovik
  Hello, t...@.

A bit tricky code in yp_all.c `val' is not freed.  It might be
allocated but might be not freed
when `key' allocation failed.

Index: lib/libc/yp/yp_all.c
===
RCS file: /OpenBSD/src/lib/libc/yp/yp_all.c,v
retrieving revision 1.9
diff -u -r1.9 yp_all.c
--- lib/libc/yp/yp_all.c5 Aug 2005 13:02:16 -   1.9
+++ lib/libc/yp/yp_all.c8 Jan 2010 12:37:25 -
@@ -78,8 +78,11 @@
}
xdr_free(xdr_ypresp_all, (char *)out);

-   if (key == NULL || val == NULL)
+   if (key == NULL || val == NULL) {
+   if (val != NULL)
+   free(val);
return FALSE;
+   }

r = (*ypresp_allfn)(status, key,
out.ypresp_all_u.val.key.keydat_len, val,



Re: [patch] patch:util.c does free memory after strdup(3)

2010-01-08 Thread Igor Zinovik
2010/1/8 Stuart Henderson s...@spacehopper.org:
 On 2010/01/08 13:33, Owain Ainsworth wrote:
 Please note that none of your patches apply because of spaces in the
 whitespace instead of tabs (I applied them manually). Either your mail
 client is mangling the diffs, or you're copy/pasting the diffs into the
 mail client. In future could you please try and stop this happening, it
 makes dealing with the patches a lot harder?

 I can recommend xclip (in packages) if you're pasting into X;
 e.g. cvs di | xclip -i then paste away.

No that not my case. My openbsd works in vm, i'm connecting to it via ssh
and sending diffs via gmail web interface. Ok, i'l just setup sendmail and mail
and will use them to send diffs.



[patch] bgplg.c probably leaks file descriptor

2010-01-07 Thread Igor Zinovik
  Hello, t...@.

Seems that bgplg.c leaks file descriptor `fd' in lg_incl(). It opens
it, but does not closes.

Index: bgplg.c
===
RCS file: /OpenBSD/src/usr.bin/bgplg/bgplg.c,v
retrieving revision 1.7
diff -u -r1.7 bgplg.c
--- bgplg.c 10 Oct 2007 13:23:40 -  1.7
+++ bgplg.c 7 Jan 2010 21:33:51 -
@@ -235,6 +235,7 @@
fwrite(buf, len, 1, stdout);
} while(len == BUFSIZ);

+   close(fd);
return (0);
 }



[patch] patch:util.c does free memory after strdup(3)

2010-01-07 Thread Igor Zinovik
  Hello, t...@.

tmpbuf is allocated via strdup(3) but it is leaved unfreed when we
leave makedirs() function.

Index: util.c
===
RCS file: /OpenBSD/src/usr.bin/patch/util.c,v
retrieving revision 1.33
diff -u -r1.33 util.c
--- util.c  27 Oct 2009 23:59:41 -  1.33
+++ util.c  7 Jan 2010 21:42:11 -
@@ -310,8 +310,10 @@

if (striplast) {
char*s = strrchr(tmpbuf, '/');
-   if (s == NULL)
+   if (s == NULL) {
+   free(tmpbuf);
return; /* nothing to be done */
+   }
*s = '\0';
}
if (mkpath(tmpbuf) != 0)