summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2007-08-25 16:10:52 +0000
committerMike Frysinger <vapier@gentoo.org>2007-08-25 16:10:52 +0000
commit355c45f85a314bc9b08b80fb58b1616671c30c99 (patch)
tree3437055db98f7d447c891b03e00097e3bdc60cef /sys-apps
parentamd64 stable, bug 173292 (diff)
downloadgentoo-2-355c45f85a314bc9b08b80fb58b1616671c30c99.tar.gz
gentoo-2-355c45f85a314bc9b08b80fb58b1616671c30c99.tar.bz2
gentoo-2-355c45f85a314bc9b08b80fb58b1616671c30c99.zip
Snipe some fixes from Fedora.
(Portage version: 2.1.3.7)
Diffstat (limited to 'sys-apps')
-rw-r--r--sys-apps/gawk/ChangeLog9
-rw-r--r--sys-apps/gawk/files/digest-gawk-3.1.5-r53
-rw-r--r--sys-apps/gawk/files/gawk-3.1.5-freewstr2.patch257
-rw-r--r--sys-apps/gawk/files/gawk-3.1.5-ipv6.patch301
-rw-r--r--sys-apps/gawk/files/gawk-3.1.5-mbread.patch41
-rw-r--r--sys-apps/gawk/gawk-3.1.5-r5.ebuild124
6 files changed, 734 insertions, 1 deletions
diff --git a/sys-apps/gawk/ChangeLog b/sys-apps/gawk/ChangeLog
index 89c55ecc79f6..4874d89b1867 100644
--- a/sys-apps/gawk/ChangeLog
+++ b/sys-apps/gawk/ChangeLog
@@ -1,6 +1,13 @@
# ChangeLog for sys-apps/gawk
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sys-apps/gawk/ChangeLog,v 1.107 2007/07/12 09:26:28 uberlord Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-apps/gawk/ChangeLog,v 1.108 2007/08/25 16:10:52 vapier Exp $
+
+*gawk-3.1.5-r5 (25 Aug 2007)
+
+ 25 Aug 2007; Mike Frysinger <vapier@gentoo.org>
+ +files/gawk-3.1.5-freewstr2.patch, +files/gawk-3.1.5-ipv6.patch,
+ +files/gawk-3.1.5-mbread.patch, +gawk-3.1.5-r5.ebuild:
+ Snipe some fixes from Fedora.
*gawk-3.1.5-r4 (12 Jul 2007)
diff --git a/sys-apps/gawk/files/digest-gawk-3.1.5-r5 b/sys-apps/gawk/files/digest-gawk-3.1.5-r5
new file mode 100644
index 000000000000..9ac602be41d5
--- /dev/null
+++ b/sys-apps/gawk/files/digest-gawk-3.1.5-r5
@@ -0,0 +1,3 @@
+MD5 4760325489479cac17fe0114b8f62f30 gawk-3.1.5.tar.gz 2310919
+RMD160 8d875f4ea9e9ef5c932468cf43c691f6e082b197 gawk-3.1.5.tar.gz 2310919
+SHA256 463dcb9d0ca398b1d4f5a332f6cd9cec56441265fca616f2ea1b44d459e9f0f8 gawk-3.1.5.tar.gz 2310919
diff --git a/sys-apps/gawk/files/gawk-3.1.5-freewstr2.patch b/sys-apps/gawk/files/gawk-3.1.5-freewstr2.patch
new file mode 100644
index 000000000000..1ec22fb8edfc
--- /dev/null
+++ b/sys-apps/gawk/files/gawk-3.1.5-freewstr2.patch
@@ -0,0 +1,257 @@
+Ripped from Fedora
+
+--- gawk-3.1.5/field.c.freewstr 2007-01-15 11:02:51.000000000 +0100
++++ gawk-3.1.5/field.c 2007-01-15 11:21:56.000000000 +0100
+@@ -155,6 +155,7 @@
+ ofs = force_string(OFS_node->var_value);
+ ofslen = ofs->stlen;
+ for (i = NF; i > 0; i--) {
++ free_wstr(fields_arr[i]);
+ tmp = fields_arr[i];
+ tmp = force_string(tmp);
+ tlen += tmp->stlen;
+@@ -922,7 +923,7 @@
+ FIELDWIDTHS[0] = 0;
+ for (i = 1; ; i++) {
+ unsigned long int tmp;
+- if (i >= fw_alloc) {
++ if (i + 1 >= fw_alloc) {
+ fw_alloc *= 2;
+ erealloc(FIELDWIDTHS, int *, fw_alloc * sizeof(int), "set_FIELDWIDTHS");
+ }
+--- gawk-3.1.5/builtin.c.freewstr 2005-07-26 20:07:43.000000000 +0200
++++ gawk-3.1.5/builtin.c 2007-01-15 11:12:52.000000000 +0100
+@@ -2089,9 +2089,9 @@
+ }
+
+ free(buf);
+- if (wc_indices != NULL)
+- free(wc_indices);
+ }
++ if (wc_indices != NULL)
++ free(wc_indices);
+ } else { /* match failed */
+ rstart = 0;
+ rlength = -1;
+@@ -2462,6 +2462,8 @@
+ free(t->stptr);
+ t->stptr = buf;
+ t->stlen = textlen;
++ free_wstr(t);
++ t->flags &= ~(NUMCUR|NUMBER);
+
+ free_temp(s);
+ if (matches > 0 && lhs) {
+@@ -2471,7 +2473,6 @@
+ }
+ if (after_assign != NULL)
+ (*after_assign)();
+- t->flags &= ~(NUMCUR|NUMBER);
+ }
+ if (mb_indices != NULL)
+ free(mb_indices);
+--- gawk-3.1.5/awk.h.freewstr 2005-07-26 20:07:43.000000000 +0200
++++ gawk-3.1.5/awk.h 2007-01-15 11:02:51.000000000 +0100
+@@ -1166,6 +1166,9 @@
+ #define force_wstring(n) str2wstr(n, NULL)
+ extern const wchar_t *wstrstr P((const wchar_t *haystack, size_t hs_len, const wchar_t *needle, size_t needle_len));
+ extern const wchar_t *wcasestrstr P((const wchar_t *haystack, size_t hs_len, const wchar_t *needle, size_t needle_len));
++extern void free_wstr P((NODE *n));
++#else
++#define free_wstr(NODE) /* empty */
+ #endif
+ /* re.c */
+ extern Regexp *make_regexp P((const char *s, size_t len, int ignorecase, int dfa));
+--- gawk-3.1.5/node.c.freewstr 2007-01-15 11:02:51.000000000 +0100
++++ gawk-3.1.5/node.c 2007-01-15 11:33:44.000000000 +0100
+@@ -96,6 +96,7 @@
+ if (! do_traditional && isnondecimal(cp, TRUE)) {
+ n->numbr = nondec2awknum(cp, cpend - cp);
+ n->flags |= NUMCUR;
++ ptr = cpend;
+ goto finish;
+ }
+ }
+@@ -218,15 +219,7 @@
+ no_malloc:
+ s->stref = 1;
+ s->flags |= STRCUR;
+-#if defined MBS_SUPPORT
+- if ((s->flags & WSTRCUR) != 0) {
+- assert(s->wstptr != NULL);
+- free(s->wstptr);
+- s->wstptr = NULL;
+- s->wstlen = 0;
+- s->flags &= ~WSTRCUR;
+- }
+-#endif
++ free_wstr(s);
+ return s;
+ }
+
+@@ -289,8 +282,14 @@
+ *r = *n;
+ r->flags &= ~(PERM|TEMP|FIELD);
+ r->flags |= MALLOC;
+-#if defined MBS_SUPPORT
++#ifdef MBS_SUPPORT
++ /*
++ * DON'T call free_wstr(r) here!
++ * r->wstptr still points at n->wstptr's value, and we
++ * don't want to free it!
++ */
+ r->wstptr = NULL;
++ r->wstlen = 0;
+ #endif /* defined MBS_SUPPORT */
+ if (n->type == Node_val && (n->flags & STRCUR) != 0) {
+ r->stref = 1;
+@@ -346,11 +345,7 @@
+ r->stref = 1;
+ r->stptr = NULL;
+ r->stlen = 0;
+-#if defined MBS_SUPPORT
+- r->wstptr = NULL;
+- r->wstlen = 0;
+- r->flags &= ~WSTRCUR;
+-#endif /* MBS_SUPPORT */
++ free_wstr(r);
+ #endif /* GAWKDEBUG */
+ return r;
+ }
+@@ -365,10 +360,11 @@
+ getnode(r);
+ r->type = Node_val;
+ r->flags = (STRING|STRCUR|MALLOC);
+-#if defined MBS_SUPPORT
++#ifdef MBS_SUPPORT
+ r->wstptr = NULL;
+ r->wstlen = 0;
+-#endif
++#endif /* defined MBS_SUPPORT */
++
+ if (flags & ALREADY_MALLOCED)
+ r->stptr = s;
+ else {
+@@ -512,20 +508,13 @@
+ return;
+ }
+ free(tmp->stptr);
+-#if defined MBS_SUPPORT
+- if (tmp->wstptr != NULL) {
+- assert((tmp->flags & WSTRCUR) != 0);
+- free(tmp->wstptr);
+- }
+- tmp->flags &= ~WSTRCUR;
+- tmp->wstptr = NULL;
+- tmp->wstlen = 0;
+-#endif
++ free_wstr(tmp);
+ }
+ freenode(tmp);
+ return;
+ }
+ if ((tmp->flags & FIELD) != 0) {
++ free_wstr(tmp);
+ freenode(tmp);
+ return;
+ }
+@@ -706,12 +695,8 @@
+ return n;
+ /* otherwise
+ fall through and recompute to fill in the array */
+- }
+-
+- if (n->wstptr != NULL) {
+- free(n->wstptr);
+- n->wstptr = NULL;
+- n->wstlen = 0;
++ if (n->wstptr != NULL)
++ free_wstr(n);
+ }
+
+ /*
+@@ -752,8 +737,8 @@
+ case (size_t) -2:
+ case (size_t) -1:
+ case 0:
+- goto done;
+-
++ count = 1;
++ /* fall through */
+ default:
+ *wsp++ = wc;
+ src_count -= count;
+@@ -777,6 +762,20 @@
+ return n;
+ }
+
++/* free_wstr --- release the wide string part of a node */
++
++void
++free_wstr(NODE *n)
++{
++ if ((n->flags & WSTRCUR) != 0) {
++ assert(n->wstptr != NULL);
++ free(n->wstptr);
++ }
++ n->wstptr = NULL;
++ n->wstlen = 0;
++ n->flags &= ~WSTRCUR;
++}
++
+ #if 0
+ static void
+ dump_wstr(FILE *fp, const wchar_t *str, size_t len)
+--- gawk-3.1.5/dfa.c.freewstr 2007-01-15 11:13:19.000000000 +0100
++++ gawk-3.1.5/dfa.c 2007-01-15 11:17:44.000000000 +0100
+@@ -516,7 +516,6 @@
+
+ work_mbc->nchars = work_mbc->nranges = work_mbc->nch_classes = 0;
+ work_mbc->nequivs = work_mbc->ncoll_elems = 0;
+- work_mbc->chars = NULL;
+ work_mbc->ch_classes = NULL;
+ work_mbc->range_sts = work_mbc->range_ends = NULL;
+ work_mbc->equivs = work_mbc->coll_elems = NULL;
+@@ -1602,8 +1601,8 @@
+ d->states[i].constraint = 0;
+ d->states[i].first_end = 0;
+ #ifdef MBS_SUPPORT
+- if (MB_CUR_MAX > 1)
+- d->states[i].mbps.nelem = 0;
++ d->states[i].mbps.nelem = 0;
++ d->states[i].mbps.elems = NULL;
+ #endif
+ for (j = 0; j < s->nelem; ++j)
+ if (d->tokens[s->elems[j].index] < 0)
+@@ -3136,8 +3135,13 @@
+ }
+ #endif /* MBS_SUPPORT */
+
+- for (i = 0; i < d->sindex; ++i)
++ for (i = 0; i < d->sindex; ++i) {
+ free((ptr_t) d->states[i].elems.elems);
++#ifdef MBS_SUPPORT
++ if (d->states[i].mbps.nelem > 0)
++ free((ptr_t) d->states[i].mbps.elems);
++#endif /* MBS_SUPPORT */
++ }
+ free((ptr_t) d->states);
+ for (i = 0; i < d->tindex; ++i)
+ if (d->follows[i].elems)
+--- gawk-3.1.5/eval.c.freewstr 2007-01-15 11:02:51.000000000 +0100
++++ gawk-3.1.5/eval.c 2007-01-15 11:02:51.000000000 +0100
+@@ -1176,13 +1176,7 @@
+ memcpy(l->stptr + l->stlen, r->stptr, r->stlen);
+ l->stlen += r->stlen;
+ l->stptr[l->stlen] = '\0';
+-#if defined MBS_SUPPORT
+- if (r->wstptr != NULL)
+- free(r->wstptr);
+- r->wstptr = NULL;
+- r->wstlen = 0;
+- r->flags &= ~WSTRCUR;
+-#endif /* MBS_SUPPORT */
++ free_wstr(l);
+ } else {
+ char *nval;
+ size_t nlen = l->stlen + r->stlen + 2;
diff --git a/sys-apps/gawk/files/gawk-3.1.5-ipv6.patch b/sys-apps/gawk/files/gawk-3.1.5-ipv6.patch
new file mode 100644
index 000000000000..1bb2345618c9
--- /dev/null
+++ b/sys-apps/gawk/files/gawk-3.1.5-ipv6.patch
@@ -0,0 +1,301 @@
+Ripped from Fedora
+
+diff -bru gawk-3.1.5.orig/io.c gawk-3.1.5/io.c
+--- gawk-3.1.5.orig/io.c 2006-07-07 16:13:08.000000000 +0200
++++ gawk-3.1.5/io.c 2006-07-10 13:18:13.000000000 +0200
+@@ -71,7 +71,6 @@
+ extern int MRL;
+
+ #ifdef HAVE_SOCKETS
+-enum inet_prot { INET_NONE, INET_TCP, INET_UDP, INET_RAW };
+
+ #ifndef SHUT_RD
+ #define SHUT_RD 0
+@@ -1133,24 +1132,60 @@
+ /* socketopen --- open a socket and set it into connected state */
+
+ static int
+-socketopen(enum inet_prot type, int localport, int remoteport, const char *remotehostname)
++socketopen(int type, const char *localpname, const char *remotepname,
++ const char *remotehostname)
+ {
+- struct hostent *hp = gethostbyname(remotehostname);
+- struct sockaddr_in local_addr, remote_addr;
++ struct addrinfo *lres, *lres0;
++ struct addrinfo lhints;
++ struct addrinfo *rres, *rres0;
++ struct addrinfo rhints;
++
++ int lerror;
++ int rerror;
++
+ int socket_fd;
+ int any_remote_host = strcmp(remotehostname, "0");
+
++ memset (&lhints, '\0', sizeof (lhints));
++ lhints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
++ lhints.ai_socktype = type;
++
++ lerror = getaddrinfo (NULL, localpname, &lhints, &lres);
++ if (lerror) {
++ if (strcmp(localpname, "0"))
++ fatal(_("local port invalid in `/inet'"));
++ lres0 = NULL;
++ lres = &lhints;
++ } else
++ lres0 = lres;
++
++ while (lres) {
++ memset (&rhints, '\0', sizeof (rhints));
++ rhints.ai_flags = lhints.ai_flags;
++ rhints.ai_socktype = lhints.ai_socktype;
++ rhints.ai_family = lhints.ai_family;
++ rhints.ai_protocol = lhints.ai_protocol;
++
++ rerror = getaddrinfo (remotehostname, remotepname, &rhints, &rres);
++ if (rerror) {
++ if (lres0)
++ freeaddrinfo(lres0);
++ fatal(_("remote host and port information invalid"));
++ }
++ rres0 = rres;
+ socket_fd = INVALID_HANDLE;
+- switch (type) {
+- case INET_TCP:
+- if (localport != 0 || remoteport != 0) {
++ while (rres) {
++ socket_fd = socket (rres->ai_family,
++ rres->ai_socktype, rres->ai_protocol);
++ if (socket_fd < 0 || socket_fd == INVALID_HANDLE)
++ goto nextrres;
++
++ if (type == SOCK_STREAM) {
+ int on = 1;
+ #ifdef SO_LINGER
+ struct linger linger;
+-
+ memset(& linger, '\0', sizeof(linger));
+ #endif
+- socket_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR,
+ (char *) & on, sizeof(on));
+ #ifdef SO_LINGER
+@@ -1160,57 +1195,27 @@
+ (char *) & linger, sizeof(linger));
+ #endif
+ }
+- break;
+- case INET_UDP:
+- if (localport != 0 || remoteport != 0)
+- socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+- break;
+- case INET_RAW:
+-#ifdef SOCK_RAW
+- if (localport == 0 && remoteport == 0)
+- socket_fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
+-#endif
+- break;
+- case INET_NONE:
+- /* fall through */
+- default:
+- cant_happen();
+- break;
+- }
++ if (bind(socket_fd, lres->ai_addr, lres->ai_addrlen) != 0)
++ goto nextrres;
+
+- if (socket_fd < 0 || socket_fd == INVALID_HANDLE
+- || (hp == NULL && any_remote_host != 0))
+- return INVALID_HANDLE;
+-
+- local_addr.sin_family = remote_addr.sin_family = AF_INET;
+- local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+- remote_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+- local_addr.sin_port = htons(localport);
+- remote_addr.sin_port = htons(remoteport);
+- if (bind(socket_fd, (struct sockaddr *) &local_addr, sizeof(local_addr)) == 0) {
+ if (any_remote_host != 0) { /* not ANY => create a client */
+- if (type == INET_TCP || type == INET_UDP) {
+- memcpy(&remote_addr.sin_addr, hp->h_addr,
+- sizeof(remote_addr.sin_addr));
+- if (connect(socket_fd,
+- (struct sockaddr *) &remote_addr,
+- sizeof(remote_addr)) != 0) {
+- close(socket_fd);
+- if (localport == 0)
+- socket_fd = INVALID_HANDLE;
+- else
+- socket_fd = socketopen(type, localport, 0, "0");
+- }
++ if (type != SOCK_RAW) {
++ if (connect(socket_fd, rres->ai_addr,
++ rres->ai_addrlen) == 0)
++ break;
+ } else {
+ /* /inet/raw client not ready yet */
+ fatal(_("/inet/raw client not ready yet, sorry"));
+ if (geteuid() != 0)
++ /* FIXME: is this second fatal ever reached? */
+ fatal(_("only root may use `/inet/raw'."));
+ }
+ } else { /* remote host is ANY => create a server */
+- if (type == INET_TCP) {
++ if (type == SOCK_STREAM) {
+ int clientsocket_fd = INVALID_HANDLE;
+- socklen_t namelen = sizeof(remote_addr);
++
++ struct sockaddr_storage remote_addr;
++ socklen_t namelen = sizeof (remote_addr);
+
+ if (listen(socket_fd, 1) >= 0
+ && (clientsocket_fd = accept(socket_fd,
+@@ -1218,25 +1223,22 @@
+ &namelen)) >= 0) {
+ close(socket_fd);
+ socket_fd = clientsocket_fd;
+- } else {
+- close(socket_fd);
+- socket_fd = INVALID_HANDLE;
++ break;
+ }
+- } else if (type == INET_UDP) {
++ } else if (type == SOCK_DGRAM) {
+ #ifdef MSG_PEEK
+ char buf[10];
++ struct sockaddr_storage remote_addr;
+ socklen_t readle;
+
+ if (recvfrom(socket_fd, buf, 1, MSG_PEEK,
+ (struct sockaddr *) & remote_addr,
+- & readle) < 1
+- || readle != sizeof(remote_addr)
+- || connect(socket_fd,
++ & readle) >= 0
++ && readle
++ && connect(socket_fd,
+ (struct sockaddr *)& remote_addr,
+- readle) != 0) {
+- close(socket_fd);
+- socket_fd = INVALID_HANDLE;
+- }
++ readle) == 0)
++ break;
+ #endif
+ } else {
+ /* /inet/raw server not ready yet */
+@@ -1245,10 +1247,20 @@
+ fatal(_("only root may use `/inet/raw'."));
+ }
+ }
+- } else {
++
++nextrres:
++ if (socket_fd != INVALID_HANDLE)
+ close(socket_fd);
+ socket_fd = INVALID_HANDLE;
++ rres = rres->ai_next;
++ }
++ freeaddrinfo(rres0);
++ if (socket_fd != INVALID_HANDLE)
++ break;
++ lres = lres->ai_next;
+ }
++ if (lres0)
++ freeaddrinfo(lres0);
+
+ return socket_fd;
+ }
+@@ -1313,30 +1325,24 @@
+ } else if (STREQN(name, "/inet/", 6)) {
+ #ifdef HAVE_SOCKETS
+ /* /inet/protocol/localport/hostname/remoteport */
+- enum inet_prot protocol = INET_NONE;
+- int localport, remoteport;
++ int protocol;
+ char *hostname;
+ char *hostnameslastcharp;
+ char *localpname;
+- char proto[4];
+- struct servent *service;
++ char *localpnamelastcharp;
+
+ cp = (char *) name + 6;
+ /* which protocol? */
+ if (STREQN(cp, "tcp/", 4))
+- protocol = INET_TCP;
++ protocol = SOCK_STREAM;
+ else if (STREQN(cp, "udp/", 4))
+- protocol = INET_UDP;
++ protocol = SOCK_DGRAM;
+ else if (STREQN(cp, "raw/", 4))
+- protocol = INET_RAW;
++ protocol = SOCK_RAW;
+ else
+ fatal(_("no (known) protocol supplied in special filename `%s'"),
+ name);
+
+- proto[0] = cp[0];
+- proto[1] = cp[1];
+- proto[2] = cp[2];
+- proto[3] = '\0';
+ cp += 4;
+
+ /* which localport? */
+@@ -1354,25 +1360,17 @@
+ * By using atoi() the use of decimal numbers is enforced.
+ */
+ *cp = '\0';
+-
+- localport = atoi(localpname);
+- if (strcmp(localpname, "0") != 0
+- && (localport <= 0 || localport > 65535)) {
+- service = getservbyname(localpname, proto);
+- if (service == NULL)
+- fatal(_("local port invalid in `%s'"), name);
+- else
+- localport = ntohs(service->s_port);
+- }
+- *cp = '/';
++ localpnamelastcharp = cp;
+
+ /* which hostname? */
+ cp++;
+ hostname = cp;
+ while (*cp != '/' && *cp != '\0')
+ cp++;
+- if (*cp != '/' || cp == hostname)
++ if (*cp != '/' || cp == hostname) {
++ *localpnamelastcharp = '/';
+ fatal(_("must supply a remote hostname to `/inet'"));
++ }
+ *cp = '\0';
+ hostnameslastcharp = cp;
+
+@@ -1386,22 +1384,15 @@
+ * Here too, require a port, let them explicitly put 0 if
+ * they don't care.
+ */
+- if (*cp == '\0')
++ if (*cp == '\0') {
++ *localpnamelastcharp = '/';
++ *hostnameslastcharp = '/';
+ fatal(_("must supply a remote port to `/inet'"));
+- remoteport = atoi(cp);
+- if (strcmp(cp, "0") != 0
+- && (remoteport <= 0 || remoteport > 65535)) {
+- service = getservbyname(cp, proto);
+- if (service == NULL)
+- fatal(_("remote port invalid in `%s'"), name);
+- else
+- remoteport = ntohs(service->s_port);
+ }
+
+- /* Open Sesame! */
+- openfd = socketopen(protocol, localport, remoteport, hostname);
++ openfd = socketopen(protocol, localpname, cp, hostname);
++ *localpnamelastcharp = '/';
+ *hostnameslastcharp = '/';
+-
+ #else /* ! HAVE_SOCKETS */
+ fatal(_("TCP/IP communications are not supported"));
+ #endif /* HAVE_SOCKETS */
diff --git a/sys-apps/gawk/files/gawk-3.1.5-mbread.patch b/sys-apps/gawk/files/gawk-3.1.5-mbread.patch
new file mode 100644
index 000000000000..078c97d1b6f1
--- /dev/null
+++ b/sys-apps/gawk/files/gawk-3.1.5-mbread.patch
@@ -0,0 +1,41 @@
+Ripped from Fedora
+
+ Date: Mon, 18 Dec 2006 18:38:13 +0300
+ From: "Dmitry V. Levin" <ldv@altlinux.org>
+ Subject: gawk: do_match() invalid read
+ To: bug-gawk@gnu.org
+
+ Due to missing mounds check, do_match() may do invalid read in multibyte
+ locales:
+
+ $ printf '\n\n' |env -i gawk '{print match(""," *")}'
+ 1
+ 1
+ $ printf '\n\n' |env -i LC_ALL=3Dru_RU.UTF-8 gawk '{print match(""," *")}'
+ -1208299079
+ 134843273
+
+ As you see, match() output in multibyte locale is wrong; valgrind reports
+ about "Invalid read of size 4".
+
+
+--- gawk-3.1.5/builtin.c.mbread 2007-01-12 13:23:55.000000000 +0100
++++ gawk-3.1.5/builtin.c 2007-01-12 13:24:41.000000000 +0100
+@@ -2020,7 +2020,7 @@
+
+ rlength = REEND(rp, t1->stptr) - RESTART(rp, t1->stptr); /* byte length */
+ #ifdef MBS_SUPPORT
+- if (gawk_mb_cur_max > 1) {
++ if (rlength > 0 && gawk_mb_cur_max > 1) {
+ t1 = str2wstr(t1, & wc_indices);
+ rlength = wc_indices[rstart + rlength - 1] - wc_indices[rstart] + 1;
+ rstart = wc_indices[rstart];
+@@ -2046,7 +2046,7 @@
+ subpat_start = s;
+ subpat_len = len = SUBPATEND(rp, t1->stptr, ii) - s;
+ #ifdef MBS_SUPPORT
+- if (gawk_mb_cur_max > 1) {
++ if (len > 0 && gawk_mb_cur_max > 1) {
+ subpat_start = wc_indices[s];
+ subpat_len = wc_indices[s + len - 1] - subpat_start + 1;
+ }
diff --git a/sys-apps/gawk/gawk-3.1.5-r5.ebuild b/sys-apps/gawk/gawk-3.1.5-r5.ebuild
new file mode 100644
index 000000000000..3fe36420de63
--- /dev/null
+++ b/sys-apps/gawk/gawk-3.1.5-r5.ebuild
@@ -0,0 +1,124 @@
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-apps/gawk/gawk-3.1.5-r5.ebuild,v 1.1 2007/08/25 16:10:52 vapier Exp $
+
+inherit eutils toolchain-funcs multilib
+
+DESCRIPTION="GNU awk pattern-matching language"
+HOMEPAGE="http://www.gnu.org/software/gawk/gawk.html"
+SRC_URI="mirror://gnu/gawk/${P}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~sparc-fbsd ~x86 ~x86-fbsd"
+IUSE="nls"
+
+RDEPEND=""
+DEPEND="${RDEPEND}
+ nls? ( sys-devel/gettext )"
+
+SFFS=${WORKDIR}/filefuncs
+
+src_unpack() {
+ unpack ${P}.tar.gz
+
+ # Copy filefuncs module's source over ...
+ cp -r "${FILESDIR}"/filefuncs "${SFFS}" || die "cp failed"
+
+ cd "${S}"
+ epatch "${FILESDIR}"/${P}-core.patch
+ epatch "${FILESDIR}"/${P}-gcc4.patch
+ epatch "${FILESDIR}"/${P}-autotools-crap.patch #139397
+ # Patches from Fedora
+ epatch "${FILESDIR}"/${PN}-3.1.3-getpgrp_void.patch
+ epatch "${FILESDIR}"/${P}-fieldwidths.patch #127163
+ epatch "${FILESDIR}"/${P}-binmode.patch
+ epatch "${FILESDIR}"/${P}-num2str.patch
+ epatch "${FILESDIR}"/${P}-internal.patch
+ epatch "${FILESDIR}"/${P}-numflags.patch
+ epatch "${FILESDIR}"/${P}-syntaxerror.patch
+ epatch "${FILESDIR}"/${P}-wconcat.patch
+ epatch "${FILESDIR}"/${P}-ipv6.patch
+ epatch "${FILESDIR}"/${P}-mbread.patch
+ epatch "${FILESDIR}"/${P}-freewstr2.patch #135931 #188740
+}
+
+src_compile() {
+ local bindir=/usr/bin
+ use userland_GNU && bindir=/bin
+ econf \
+ --bindir=${bindir} \
+ --libexec='$(libdir)/misc' \
+ $(use_enable nls) \
+ --enable-switch \
+ || die
+ emake || die "emake failed"
+
+ cd "${SFFS}"
+ emake CC=$(tc-getCC) || die "filefuncs emake failed"
+}
+
+src_install() {
+ emake install DESTDIR="${D}" || die "install failed"
+ cd "${SFFS}"
+ emake LIBDIR="$(get_libdir)" install || die "filefuncs install failed"
+
+ dodir /usr/bin
+ # In some rare cases, (p)gawk gets installed as (p)gawk- and not
+ # (p)gawk-${PV} ... Also make sure that /bin/(p)gawk is a symlink
+ # to /bin/(p)gawk-${PV}.
+ local bindir=/usr/bin binpath= x=
+ use userland_GNU && bindir=/bin
+ for x in gawk pgawk igawk ; do
+ [[ ${x} == "gawk" ]] \
+ && binpath=${bindir} \
+ || binpath=/usr/bin
+
+ if [[ -f ${D}/${bindir}/${x} && ! -f ${D}/${bindir}/${x}-${PV} ]] ; then
+ mv -f "${D}"/${bindir}/${x} "${D}"/${binpath}/${x}-${PV}
+ elif [[ -f ${D}/${bindir}/${x}- && ! -f ${D}/${bindir}/${x}-${PV} ]] ; then
+ mv -f "${D}"/${bindir}/${x}- "${D}"/${binpath}/${x}-${PV}
+ elif [[ ${binpath} == "/usr/bin" && -f ${D}/${bindir}/${x}-${PV} ]] ; then
+ mv -f "${D}"/${bindir}/${x}-${PV} "${D}"/${binpath}/${x}-${PV}
+ fi
+
+ rm -f "${D}"/${bindir}/${x}
+ [[ -x "${D}"/${binpath}/${x}-${PV} ]] && dosym ${x}-${PV} ${binpath}/${x}
+ if use userland_GNU ; then
+ [[ ${binpath} == "/usr/bin" ]] && dosym /usr/bin/${x}-${PV} /bin/${x}
+ fi
+ done
+
+ rm -f "${D}"/bin/awk
+ dodir /usr/bin
+ # Compat symlinks
+ dosym gawk-${PV} ${bindir}/awk
+ dosym ${bindir}/gawk-${PV} /usr/bin/awk
+ if use userland_GNU ; then
+ dosym /bin/gawk-${PV} /usr/bin/gawk
+ else
+ rm -f "${D}"/{,usr/}bin/awk{,-${PV}}
+ fi
+
+ # Install headers
+ insinto /usr/include/awk
+ doins "${S}"/*.h || die "ins headers failed"
+ # We do not want 'acconfig.h' in there ...
+ rm -f "${D}"/usr/include/awk/acconfig.h
+
+ cd "${S}"
+ rm -f "${D}"/usr/share/man/man1/pgawk.1
+ dosym gawk.1 /usr/share/man/man1/pgawk.1
+ if use userland_GNU ; then
+ dosym gawk.1 /usr/share/man/man1/awk.1
+ fi
+ dodoc AUTHORS ChangeLog FUTURES LIMITATIONS NEWS PROBLEMS POSIX.STD README
+ docinto README_d
+ dodoc README_d/*
+ docinto awklib
+ dodoc awklib/ChangeLog
+ docinto pc
+ dodoc pc/ChangeLog
+ docinto posix
+ dodoc posix/ChangeLog
+}