Removing unnecessary assert from lib/libc/locale/wcscoll.c

2013-03-09 Thread Vladimir Támara Patiño

--- /usr/src53orig/lib/libc/locale/wcscoll.cSat Feb  9 14:26:52 2013
+++ wcscoll.c   Sat Mar  9 22:44:07 2013
@@ -27,7 +27,6 @@
 * SUCH DAMAGE.
 */

-#include 

#include 
  
/*



--
Dios, gracias por tu amor infinito.
--  
 Vladimir Támara Patiño.  http://vtamara.pasosdeJesus.org/

 http://www.pasosdejesus.org/dominio_publico_colombia.html



Order in variables of lib/libc/locale/Makefile.inc

2013-03-09 Thread Vladimir Támara Patiño

For example lib/libc/string/Makefile.inc has values of
SRCS, MAN and MLINK ordered alphabetically, making easier
to know where to add new values to those variables.

Trying the same with lib/libc/locale/Makefile with attached patch.


--
Dios, gracias por tu amor infinito.
--  
 Vladimir Támara Patiño.  http://vtamara.pasosdeJesus.org/

 http://www.pasosdejesus.org/dominio_publico_colombia.html

--- Makefile.inc.orig   Sat Mar  9 11:16:47 2013
+++ Makefile.incSat Mar  9 11:21:13 2013
@@ -3,21 +3,27 @@
 # locale sources
 .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/locale ${LIBCSRCDIR}/locale
 
-SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
-   localeconv.c nl_langinfo.c setlocale.c iswctype.c __mb_cur_max.c \
-   mblen.c mbrlen.c mbstowcs.c mbtowc.c multibyte_citrus.c wcscoll.c \
-   wcstombs.c wctob.c wctomb.c wcstof.c wcstod.c wcstold.c wcstol.c \
-   wcstoul.c wcstoll.c wcstoull.c wcstoimax.c wcstoumax.c \
-   setrunelocale.c runeglue.c rune.c runetable.c ___runetype_mb.c \
-   _wctrans.c wcsxfrm.c
+SRCS+= btowc.c \
+   _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
+   iswctype.c localeconv.c __mb_cur_max.c \
+   mblen.c mbrlen.c mbstowcs.c mbtowc.c \
+   multibyte_citrus.c nl_langinfo.c \
+   rune.c runeglue.c runetable.c ___runetype_mb.c \
+   setrunelocale.c setlocale.c \
+   _wctrans.c wcscoll.c wcstoimax.c wcstod.c wcstof.c \
+   wcstol.c wcstold.c wcstoll.c wcstombs.c wcstoul.c wcstoull.c \
+   wcstoumax.c wcsxfrm.c wctob.c wctomb.c 
 
-MAN+=  nl_langinfo.3 setlocale.3 iswalnum.3 towlower.3 \
-   btowc.3 mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 mbsrtowcs.3 \
-   mbstowcs.3 mbtowc.3 wcrtomb.3 wcsrtombs.3 wcstod.3 wcstol.3 \
-   wcstombs.3 wctob.3 wctomb.3 \
-   wctype.3 iswctype.3 wctrans.3 towctrans.3 wcwidth.3
-MLINKS+=setlocale.3 localeconv.3 \
-   iswalnum.3 iswalpha.3 \
+MAN+=   btowc.3 iswalnum.3 iswctype.3 \
+   mblen.3 mbrlen.3 mbrtowc.3 \
+   mbsinit.3 mbsrtowcs.3 mbstowcs.3 mbtowc.3 \
+   nl_langinfo.3 setlocale.3 \
+   towctrans.3 towlower.3 \
+   wcrtomb.3 wcsrtombs.3 \
+   wcstod.3 wcstol.3 wcstombs.3 \
+   wctob.3 wctomb.3 wctrans.3 wctype.3 wcwidth.3
+
+MLINKS+= iswalnum.3 iswalpha.3 \
iswalnum.3 iswblank.3 \
iswalnum.3 iswcntrl.3 \
iswalnum.3 iswdigit.3 \
@@ -28,15 +34,16 @@
iswalnum.3 iswspace.3 \
iswalnum.3 iswupper.3 \
iswalnum.3 iswxdigit.3 \
+   mbsrtowcs.3 mbsnrtowcs.3 \
+   setlocale.3 localeconv.3 \
towlower.3 towupper.3 \
+   wcsrtombs.3 wcsnrtombs.3 \
wcstod.3 wcstof.3 \
wcstod.3 wcstold.3 \
wcstol.3 wcstoul.3 \
wcstol.3 wcstoll.3 \
wcstol.3 wcstoull.3 \
wcstol.3 wcstoimax.3 \
-   wcstol.3 wcstoumax.3 \
-   mbsrtowcs.3 mbsnrtowcs.3 \
-   wcsrtombs.3 wcsnrtombs.3
+   wcstol.3 wcstoumax.3 
 
 CFLAGS+=-I${.CURDIR} -I${LIBCSRCDIR}/citrus


gzsig: avoid endless loop on input error

2013-03-09 Thread Tobias Stoeckmann
Hi,

while skipping some header sections of a *.gz file, gzsig uses the
function getc without taking a possible EOF return value into account.

On error, the tool should obviously stop with an error message, therefore
leaving sign() or verify() with -1.


Tobias

Index: sign.c
===
RCS file: /cvs/src/usr.bin/gzsig/sign.c,v
retrieving revision 1.9
diff -u -p -r1.9 sign.c
--- sign.c  12 Oct 2007 19:52:06 -  1.9
+++ sign.c  9 Mar 2013 22:41:53 -
@@ -114,12 +114,12 @@ embed_signature(struct key *key, FILE *f
offset = ftell(fin);
 
if (gh.flags & GZIP_FNAME) {
-   while (getc(fin) != '\0')
-   ;
+   if (skip_string(fin))
+   return (-1);
}
if (gh.flags & GZIP_FCOMMENT) {
-   while (getc(fin) != '\0')
-   ;
+   if (skip_string(fin))
+   return (-1);
}
if (gh.flags & GZIP_FENCRYPT) {
if (fread(buf, 1, GZIP_FENCRYPT_LEN, fin) != GZIP_FENCRYPT_LEN)
Index: util.c
===
RCS file: /cvs/src/usr.bin/gzsig/util.c,v
retrieving revision 1.2
diff -u -p -r1.2 util.c
--- util.c  28 May 2005 08:07:45 -  1.2
+++ util.c  9 Mar 2013 22:41:53 -
@@ -62,6 +62,17 @@ copy_permissions(char *srcfile, char *ds
return (0);
 }
 
+int
+skip_string(FILE *fin)
+{
+   int c;
+
+   while ((c = getc(fin)) != '\0')
+   if (c == EOF)
+   return (-1);
+   return (0);
+}
+
 void
 fatal(int status, const char *fmt, ...)
 {
Index: util.h
===
RCS file: /cvs/src/usr.bin/gzsig/util.h,v
retrieving revision 1.2
diff -u -p -r1.2 util.h
--- util.h  28 May 2005 08:07:45 -  1.2
+++ util.h  9 Mar 2013 22:41:53 -
@@ -34,6 +34,7 @@
 #ifndef UTIL_H
 
 intcopy_permissions(char *srcfile, char *dstfile);
+intskip_string(FILE *fin);
 void   fatal(int status, const char *fmt, ...);
 
 #endif /* UTIL_H */
Index: verify.c
===
RCS file: /cvs/src/usr.bin/gzsig/verify.c,v
retrieving revision 1.7
diff -u -p -r1.7 verify.c
--- verify.c12 Oct 2007 19:52:06 -  1.7
+++ verify.c9 Mar 2013 22:41:53 -
@@ -105,12 +105,12 @@ verify_signature(struct key *key, FILE *
}
/* Skip over any options. */
if (gh.flags & GZIP_FNAME) {
-   while (getc(fin) != '\0')
-   ;
+   if (skip_string(fin))
+   return (-1);
}
if (gh.flags & GZIP_FCOMMENT) {
-   while (getc(fin) != '\0')
-   ;
+   if (skip_string(fin))
+   return (-1);
}
if (gh.flags & GZIP_FENCRYPT &&
fread(buf, 1, GZIP_FENCRYPT_LEN, fin) != GZIP_FENCRYPT_LEN)



race condition in gzsig

2013-03-09 Thread Tobias Stoeckmann
Hi,

there is a race condition in gzsig.  It needs some fancy vector to step in,
but better safe than sorry (especially if the fix is pretty cheap).

The race happens between opening the input file and applying the access
rights to the temporary one.  If an attacker is able to replace the input
file between opening it and stat()ing it, he could manipulate the caller
of gzsig to change the rights of the result file.

Someone agrees? OK? ;)


Tobias

Index: sign.c
===
RCS file: /cvs/src/usr.bin/gzsig/sign.c,v
retrieving revision 1.9
diff -u -p -r1.9 sign.c
--- sign.c  12 Oct 2007 19:52:06 -  1.9
+++ sign.c  9 Mar 2013 16:49:17 -
@@ -285,7 +285,7 @@ sign(int argc, char *argv[])
close(fd);
continue;
}
-   if (copy_permissions(gzipfile, tmppath) < 0) {
+   if (copy_permissions(fileno(fin), fd) < 0) {
fprintf(stderr, "Error initializing %s: %s\n",
tmppath, strerror(errno));
fclose(fin);
Index: util.c
===
RCS file: /cvs/src/usr.bin/gzsig/util.c,v
retrieving revision 1.2
diff -u -p -r1.2 util.c
--- util.c  28 May 2005 08:07:45 -  1.2
+++ util.c  9 Mar 2013 16:49:17 -
@@ -46,17 +46,17 @@
 #include "util.h"
 
 int
-copy_permissions(char *srcfile, char *dstfile)
+copy_permissions(int srcfd, int dstfd)
 {
struct stat st;
 
-   if (stat(srcfile, &st) < 0)
+   if (fstat(srcfd, &st) < 0)
return (-1);
 
-   if (chmod(dstfile, st.st_mode) < 0)
+   if (fchmod(dstfd, st.st_mode) < 0)
return (-1);
 
-   if (chown(dstfile, st.st_uid, st.st_gid) < 0)
+   if (fchown(dstfd, st.st_uid, st.st_gid) < 0)
return (-1);
 
return (0);
Index: util.h
===
RCS file: /cvs/src/usr.bin/gzsig/util.h,v
retrieving revision 1.2
diff -u -p -r1.2 util.h
--- util.h  28 May 2005 08:07:45 -  1.2
+++ util.h  9 Mar 2013 16:49:17 -
@@ -1,3 +1,4 @@
+/* $OpenBSD$ */
 /*
  * util.h
  *
@@ -33,7 +34,7 @@
 
 #ifndef UTIL_H
 
-intcopy_permissions(char *srcfile, char *dstfile);
+intcopy_permissions(int srcfd, int dstfd);
 void   fatal(int status, const char *fmt, ...);
 
 #endif /* UTIL_H */



Re: Fix gem(4) by attaching the right PHY on PowerMac G5

2013-03-09 Thread Kirill Bychkov
On Fri, March 8, 2013 13:42, Martin Pieuchot wrote:
> kirby@ reported [0] back in February that the gem(4) on his PowerMac
> G5 wasn't working. Apparently the logic to determine which PHY to use
> doesn't work with these machines when the firmware has powered down the
> chip. At least that's what FreeBSD and linux code say and it seems to
> correspond to the behavior I observed: when the NIC is used for
> netbooting the correct PHY is attached.
>
> Diff below is taken from FreeBSD and force the use of the internal PHY
> on Apple models. This makes the gem(4) on my PowerMac G5 usable even if
> I don't netboot. I also verified that it does not introduce a regression
> on my G4.
>
> Ok?

My G5's gem now works. Thanks!
gem0 at pci7 dev 15 function 0 "Apple K2 GMAC" rev 0x00: irq 41, address
00:0a:95:8f:3d:84
brgphy0 at gem0 phy 1: BCM54K2 10/100/1000baseT PHY, rev. 0

No regression on my PoweBook4,3.

> [0] http://marc.info/?l=openbsd-misc&m=136074529112590&w=2
>
>
> Index: gem.c
> ===
> RCS file: /cvs/src/sys/dev/ic/gem.c,v
> retrieving revision 1.98
> diff -u -p -r1.98 gem.c
> --- gem.c 1 Dec 2012 10:04:58 -   1.98
> +++ gem.c 7 Mar 2013 16:52:31 -
> @@ -275,11 +275,14 @@ gem_config(struct gem_softc *sc)
>   MII_OFFSET_ANY, mii_flags);
>   }
>
> - /*
> + /*
>* Fall back on an internal PHY if no external PHY was found.
> +  * Note that with Apple (K2) GMACs GEM_MIF_CONFIG_MDI0 can't be
> +  * trusted when the firmware has powered down the chip
>*/
>   child = LIST_FIRST(&mii->mii_phys);
> - if (child == NULL && sc->sc_mif_config & GEM_MIF_CONFIG_MDI0) {
> + if (child == NULL &&
> + (sc->sc_mif_config & GEM_MIF_CONFIG_MDI0 || GEM_IS_APPLE(sc))) {
>   sc->sc_mif_config &= ~GEM_MIF_CONFIG_PHY_SEL;
>   bus_space_write_4(sc->sc_bustag, sc->sc_h1,
>   GEM_MIF_CONFIG, sc->sc_mif_config);
> Index: gemvar.h
> ===
> RCS file: /cvs/src/sys/dev/ic/gemvar.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 gemvar.h
> --- gemvar.h  20 Sep 2010 07:40:41 -  1.26
> +++ gemvar.h  7 Mar 2013 16:50:39 -
> @@ -151,6 +151,10 @@ struct gem_softc {
>  #define GEM_APPLE_GMAC   3   /* Apple GMAC */
>  #define GEM_APPLE_K2_GMAC4   /* Apple K2 GMAC */
>
> +#define  GEM_IS_APPLE(sc)
> \
> + ((sc)->sc_variant == GEM_APPLE_GMAC ||  \
> +  (sc)->sc_variant == GEM_APPLE_K2_GMAC)
> +
>   u_int   sc_flags;   /* */
>  #define  GEM_GIGABIT 0x0001  /* has a gigabit PHY */
>
>




Re: Collation support (minimal)

2013-03-09 Thread Stefan Sperling
On Fri, Mar 08, 2013 at 08:10:23AM -0500, Vladimir Támara Patiño wrote:
> 
> Following the advice of Stefan Sperling (see
> http://marc.info/?l=openbsd-tech&m=136029207723238&w=4 )
> the attached patch is minimal to support collation in
> OpenBSD-current it works with ISO-8859-1 and UTF-8 translatable
> to ISO-8859-1.   It includes:
> * Program colldef to generate collation tables  (for single-byte
>  encodings)
> * Collation tables for spanish to be generated  in
> /usr/share/locale. * Implementation of strcoll, wcscoll, strxfrm and
> wcsxfrm having into account that these functions are particular
> cases of strcoll_l, wcscoll_l, strxfrm_l and wcsxfrm_l from xlocale
> and that in near future possibly OpenBSD will implement xlocale
> * Small changes to documentation * Regression test (test spanish
> with ISO-8859-1 and specially UTF-8)
> 
> The implementation is based on the one I sent before
> ( http://marc.info/?l=openbsd-tech&m=136050321323182&w=4 and
> http://marc.info/?l=openbsd-tech&m=136034304709498&w=4 ), that in
> turn is based on FreeBSD implementation.

Thanks! This looks a bit better but is still too large for my taste.

I'd like to concentrate on collation. To properly review your diff,
I need to understand what needs to be added to OpenBSD' locale implementation.
But I cannot clearly see that from reading your diff. There is still so much
unrelated stuff in there. I'll cross-check other sources of information such
as POSIX as additional references, of course. But first I need to understand
what your new code really wants to do.

It looks like your approach to adding collation support to OpenBSD is
to take FreeBSD's code as a starting point and fudge that code into
OpenBSD's libc. This approach reduces the quality of the code you end
up with and makes it hard to review your changes.

Instead, you should consider OpenBSD's code as your starting point.
And add to that _only_ what needs to be done to support collation.

Adding new functions like strxfrm_l() etc. just doesn't make sense to me.
You shouldn't need to add any new functions. We already have strcoll()
and strxfrm(). Those are interfaces from C89, so they're a bit dated.
But they should be good enough for getting some basic collation support
going. We can talk about adding support for newer interfaces later, but
those should not matter for the initial implementation.

If it helps, consider writing a new, clean, and small collation
implementation for our libc, using C89 interfaces. Instead of porting
over FreeBSD's implementation. If you can reuse bits from FreeBSD for your
own implementation, fine (just don't forget to copy licence information).
But adjust whatever FreeBSD code you use to fit our libc's model.
Don't adjust our libc to fit FreeBSD's model.

You have other unrelated changes in there, such as shuffling of MLINKS lists.
Those add noise to the diff and make it harder to review.