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-cvs&m=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] 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] lpd(8) memory leak fix

2010-03-21 Thread Igor Zinovik

Hello, tech@

After snprintf(3) call `dir' is no longer needed so free it also on normal
code path.

Index: info_passwd.c
===
RCS file: /cvs/src/usr.sbin/amd/amd/info_passwd.c,v
retrieving revision 1.7
diff -u -p -r1.7 info_passwd.c
--- info_passwd.c   2 Jun 2003 23:36:51 -   1.7
+++ info_passwd.c   21 Mar 2010 21:28:04 -
@@ -136,6 +136,7 @@ passwd_search(mnt_map *m, char *map, cha
snprintf(val, sizeof(val),
"rfs:=%s/%s;rhost:=%s;sublink:=%s;fs:=${autodir}%s",
dir, rhost, rhost, user, pw->pw_dir);
+   free(dir);
if (q)
*q = '.';
*pval = strdup(val);



[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] 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] 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] 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] 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 :
> 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 
#
# 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::

[patch] several missing closedir() in libexec/ld.so/ldconfig/ldconfig.c

2010-01-24 Thread Igor Zinovik
  Hello, tech@

Index: libexec/ld.so/ldconfig/ldconfig.c
===
RCS file: /OpenBSD/src/libexec/ld.so/ldconfig/ldconfig.c,v
retrieving revision 1.26
diff -u -r1.26 ldconfig.c
--- libexec/ld.so/ldconfig/ldconfig.c   19 Aug 2009 19:38:17 -  1.26
+++ libexec/ld.so/ldconfig/ldconfig.c   8 Jan 2010 12:04:36 -
@@ -247,6 +247,7 @@
ndewey = getdewey(dewey, cp + 4);
enter(dir, dp->d_name, name, dewey, ndewey);
}
+   closedir(dd);
return 0;
 }



Index: libexec/ld.so/ldconfig/prebind.c
===
RCS file: /OpenBSD/src/libexec/ld.so/ldconfig/prebind.c,v
retrieving revision 1.11
diff -u -r1.11 prebind.c
--- libexec/ld.so/ldconfig/prebind.c30 May 2009 23:37:03 -  1.11
+++ libexec/ld.so/ldconfig/prebind.c8 Jan 2010 12:06:49 -
@@ -281,6 +281,7 @@
;
}
}
+   closedir(dirp);
 }

 /*

Index: libexec/ld.so/ldconfig/prebind_delete.c
===
RCS file: /OpenBSD/src/libexec/ld.so/ldconfig/prebind_delete.c,v
retrieving revision 1.9
diff -u -r1.9 prebind_delete.c
--- libexec/ld.so/ldconfig/prebind_delete.c 8 Jun 2008 02:40:49
-   1.9
+++ libexec/ld.so/ldconfig/prebind_delete.c 8 Jan 2010 12:07:49 -
@@ -118,6 +118,7 @@
;
}
}
+   closedir(dirp);
return ret;
 }



[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] arlad/fprio.c file handle leak

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

Sorry for mangled diff, still have no time to setup my sendmail.  BTW
where to send patches that fix apache modules, i think that apache 1.3
is no longer maintained?

Index: usr.sbin/afs/src/arlad/fprio.c
===
RCS file: /OpenBSD/src/usr.sbin/afs/src/arlad/fprio.c,v
retrieving revision 1.5
diff -u -r1.5 fprio.c
--- usr.sbin/afs/src/arlad/fprio.c  5 Aug 2003 08:42:41 -   1.5
+++ usr.sbin/afs/src/arlad/fprio.c  8 Jan 2010 12:16:51 -
@@ -228,6 +228,7 @@
fid.Cell = cellnum;
fprio_set(fid, prio ? TRUE : FALSE);
 }
+fclose(fp);
 return 0;
 }



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

2010-01-08 Thread Igor Zinovik
2010/1/8 Stuart Henderson :
> 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] 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,



[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] /usr/src/lib/libc/hash/helper.c

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

HASHFileChunk leaks file descriptor `fd'.

Index: lib/libc/hash/helper.c
===
RCS file: /OpenBSD/src/lib/libc/hash/helper.c,v
retrieving revision 1.8
diff -u -r1.8 helper.c
--- lib/libc/hash/helper.c  8 Aug 2005 08:05:35 -   1.8
+++ lib/libc/hash/helper.c  8 Jan 2010 11:49:26 -
@@ -62,8 +62,10 @@
}
len = sb.st_size;
}
-   if (off > 0 && lseek(fd, off, SEEK_SET) < 0)
+   if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+   close(fd);
return (NULL);
+   }

while ((nr = read(fd, buffer, MIN(sizeof(buffer), len))) > 0) {
HASHUpdate(&ctx, buffer, (size_t)nr);



[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)



[patch] pwd_mkdb does closes file descriptors after copy

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

pwd_mkdb copies one file to another in cp() function.  It opens two
file descriptors with open(2),
but it does not closes them with close(2).

Index: pwd_mkdb.c
===
RCS file: /OpenBSD/src/usr.sbin/pwd_mkdb/pwd_mkdb.c,v
retrieving revision 1.42
diff -u -r1.42 pwd_mkdb.c
--- pwd_mkdb.c  27 Oct 2009 23:59:54 -  1.42
+++ pwd_mkdb.c  7 Jan 2010 21:39:01 -
@@ -394,6 +394,8 @@
errno = sverrno;
error(buf);
}
+   close(to_fd);
+   close(from_fd);
 }

 void



[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);
 }



Automatic package mirror discovery implementation for pkg_add(1) tool

2009-12-05 Thread Igor Zinovik
 think that espie@ can explain why such
functionality
wasn't implemented (because for me i think that it is not so hard to implement
fully functional package mirror discovery), maybe there are some ideological
constrains or something else. So i'm posting it here with hope that i will gain
positive feedback.

Currently my code has tons of limitations.  Here is my TODO list:
- integrate AutoMirrorDiscovery into pkg_add
- handle -stable revision
- handle -current revision (when calls uname -r)
- handle `snapshots'
- implement HTTP mirrors support
- handle HTTP mirrors without LWP, since it is not available in base
  (better to make separate Perl module, instead of hacking this one)
- implement AFS mirrors support (maybe an overkill?)
- implement RSYNC mirrors support (maybe an overkill?)
- make it FASTER!!! (it need to be profiled with dprofpp)
- better error handling
- handle situation when Internet connection goes through proxy
- handle situation when icmp pings are prohibited
- implement mirror cache (partly implemented)
  (mirrors that are sorted by response time, some kind of a file in
/var/db/pkgmirror.cache)
- handle link loss situation gracefully
- handle signal interruption

So if you want to test this piece of code just create /etc/ftp.mirrors
with following
content:
# cat /etc/ftp.mirrors
ftp://anga.funkfeuer.at/pub/OpenBSD/
ftp://carroll.cac.psu.edu/pub/OpenBSD/
ftp://filedump.se.rit.edu/pub/OpenBSD/
ftp://ftp-stud.fht-esslingen.de/pub/OpenBSD/
ftp://ftp.arcane-networks.fr/pub/OpenBSD/
ftp://ftp.aso.ee/pub/OpenBSD/
ftp://ftp.belnet.be/packages/openbsd/
ftp://ftp.bytemine.net/pub/OpenBSD/
ftp://ftp.ca.openbsd.org/pub/OpenBSD/
ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/
ftp://ftp.chg.ru/pub/OpenBSD/
ftp://ftp.crans.org/pub/OpenBSD/
ftp://ftp.cs.pu.edu.tw/BSD/OpenBSD/
ftp://ftp.cse.buffalo.edu/pub/OpenBSD/
ftp://ftp.das.ufsc.br/pub/OpenBSD/
ftp://ftp.df.lth.se/pub/OpenBSD/
ftp://ftp.dkuug.dk/pub/OpenBSD/
ftp://ftp.duth.gr/pub/OpenBSD/
ftp://ftp.esat.net/pub/OpenBSD/
ftp://ftp.estpak.ee/pub/OpenBSD/
ftp://ftp.eu.openbsd.org/pub/OpenBSD/
ftp://ftp.fmed.uc.pt/pub/OpenBSD/
ftp://ftp.fr.openbsd.org/pub/OpenBSD/
ftp://ftp.freebsdchina.org/pub/OpenBSD/
ftp://ftp.freenet.de/pub/ftp.openbsd.org/pub/OpenBSD/
ftp://ftp.fsn.hu/pub/OpenBSD/
ftp://ftp.gamma.ru/pub/OpenBSD/
ftp://ftp.heanet.ie/pub/OpenBSD/
ftp://ftp.iinet.net.au/pub/OpenBSD/
ftp://ftp.inet.no/pub/OpenBSD/
ftp://ftp.irisa.fr/pub/OpenBSD/
ftp://ftp.is.co.za/mirror/ftp.openbsd.org/
ftp://ftp.jaist.ac.jp/pub/OpenBSD/
ftp://ftp.jyu.fi/pub/OpenBSD/
ftp://ftp.kaist.ac.kr/pub/OpenBSD/
ftp://ftp.kddlabs.co.jp/OpenBSD/
ftp://ftp.lambdaserver.com/pub/OpenBSD/
ftp://ftp.mirrorservice.org/pub/OpenBSD/
ftp://ftp.netbsd.se/OpenBSD/
ftp://ftp.nluug.nl/pub/OpenBSD/
ftp://ftp.obsd.si/pub/OpenBSD/
ftp://ftp.openbsd.dk/pub/OpenBSD/
ftp://ftp.openbsd.or.id/pub/OpenBSD/
ftp://ftp.openbsd.org.ar/pub/OpenBSD/
ftp://ftp.openbsd.org/pub/OpenBSD/
ftp://ftp.piotrkosoft.net/pub/OpenBSD/
ftp://ftp.plig.net/pub/OpenBSD/
ftp://ftp.rediris.es/pub/OpenBSD/
ftp://ftp.spline.de/pub/OpenBSD/
ftp://ftp.task.gda.pl/pub/OpenBSD/
ftp://ftp.tcc.edu.tw/pub/OpenBSD/
ftp://ftp.tpnet.pl/pub/OpenBSD/
ftp://ftp.tw.openbsd.org/pub/OpenBSD/
ftp://ftp.udc.es/pub/OpenBSD/
ftp://ftp.ulak.net.tr/OpenBSD/
ftp://ftp.uninett.no/pub/OpenBSD/
ftp://ftp.wu-wien.ac.at/pub/OpenBSD/
ftp://ftp2.fr.openbsd.org/pub/OpenBSD/
ftp://ftp3.usa.openbsd.org/pub/OpenBSD/
ftp://ftp5.usa.openbsd.org/pub/OpenBSD/
ftp://gulus.usherbrooke.ca/pub/distro/OpenBSD/
ftp://mirror.aarnet.edu.au/pub/OpenBSD/
ftp://mirror.cdmon.com/pub/OpenBSD/
ftp://mirror.corbina.net/pub/OpenBSD/
ftp://mirror.hostfuss.com/pub/OpenBSD/
ftp://mirror.iawnet.sandia.gov/pub/OpenBSD/
ftp://mirror.internode.on.net/pub/OpenBSD/
ftp://mirror.pacific.net.au/OpenBSD/
ftp://mirror.planetunix.net/pub/OpenBSD/
ftp://mirror.public-internet.co.uk/pub/OpenBSD/
ftp://mirror.rit.edu/pub/OpenBSD/
ftp://mirror.roothell.org/pub/OpenBSD/
ftp://mirror.switch.ch/pub/OpenBSD/
ftp://mirrors.24-7-solutions.net/pub/OpenBSD/
ftp://mirrors.localhost.net.ar/pub/OpenBSD/
ftp://mirrors.nic.funet.fi/pub/OpenBSD/
ftp://mirrors.ucr.ac.cr/OpenBSD/
ftp://obsd.cec.mtu.edu/pub/OpenBSD/
ftp://openbsd.arcticnetwork.ca/pub/OpenBSD/
ftp://openbsd.bsdforen.de/pub/OpenBSD/
ftp://openbsd.ftp.fu-berlin.de/pub/OpenBSD/
ftp://openbsd.mirror.frontiernet.net/pub/OpenBSD/
ftp://openbsd.mirrors.pair.com/
ftp://openbsd.mirrors.tds.net/pub/OpenBSD/
ftp://openbsd.noc.jgm.gov.ar/pub/OpenBSD/


So here is the code itself (i hope GMail editor wont screw it):
#!/usr/bin/perl

# ex:ts=8 sw=4:
# $OpenBSD$
# Copyright (c) 2009 Igor Zinovik 
#
# 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
# MERCHANT