diff options
author | cf46844 <none@none> | 2006-05-25 10:46:18 -0700 |
---|---|---|
committer | cf46844 <none@none> | 2006-05-25 10:46:18 -0700 |
commit | 83efe03b07f2c50424cb88af7a19d789200bf17c (patch) | |
tree | f48639702d20b00d130a012457bc830b8880d586 /usr/src/cmd/awk/run.c | |
parent | 830233f85efba828df8e4d8993aa6d1201c7930c (diff) | |
download | illumos-joyent-83efe03b07f2c50424cb88af7a19d789200bf17c.tar.gz |
6413730 nawk sub/gsub incorrectly handle backslashes in replacement strings
Contributed by Hiroshi Nakano <nakano@math.ryukoku.ac.jp>
Diffstat (limited to 'usr/src/cmd/awk/run.c')
-rw-r--r-- | usr/src/cmd/awk/run.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/usr/src/cmd/awk/run.c b/usr/src/cmd/awk/run.c index 2088755524..6c6dfc1e37 100644 --- a/usr/src/cmd/awk/run.c +++ b/usr/src/cmd/awk/run.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -1764,9 +1763,10 @@ sub(Node **a, int nnn) sptr = getsval(y); while (*sptr != 0) { expand_buf(&buf, &bsize, cnt); - if (*sptr == '\\' && *(sptr+1) == '&') { + if (*sptr == '\\' && + (*(sptr+1) == '&' || *(sptr+1) == '\\')) { sptr++; /* skip \, */ - buf[cnt++] = *sptr++; /* add & */ + buf[cnt++] = *sptr++; /* add & or \ */ } else if (*sptr == '&') { expand_buf(&buf, &bsize, cnt + patlen); sptr++; @@ -1831,7 +1831,8 @@ gsub(Node **a, int nnn) while (*sptr != 0) { expand_buf(&buf, &bsize, cnt); if (*sptr == '\\' && - *(sptr+1) == '&') { + (*(sptr+1) == '&' || + *(sptr+1) == '\\')) { sptr++; buf[cnt++] = *sptr++; } else if (*sptr == '&') { @@ -1864,7 +1865,9 @@ gsub(Node **a, int nnn) sptr = rptr; while (*sptr != 0) { expand_buf(&buf, &bsize, cnt); - if (*sptr == '\\' && *(sptr+1) == '&') { + if (*sptr == '\\' && + (*(sptr+1) == '&' || + *(sptr+1) == '\\')) { sptr++; buf[cnt++] = *sptr++; } else if (*sptr == '&') { |