Module Name:    src
Committed By:   ginsbach
Date:           Fri Mar  9 18:54:28 UTC 2012

Modified Files:
        src/usr.bin/gencat: gencat.c

Log Message:
Improve the handling of quoted messages.
- warn about messages with an unexpected quote character
- warn about extra characters after a quote character
- warn about an unterminated quoted message


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/gencat/gencat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gencat/gencat.c
diff -u src/usr.bin/gencat/gencat.c:1.34 src/usr.bin/gencat/gencat.c:1.35
--- src/usr.bin/gencat/gencat.c:1.34	Thu Dec 29 22:58:27 2011
+++ src/usr.bin/gencat/gencat.c	Fri Mar  9 18:54:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: gencat.c,v 1.34 2011/12/29 22:58:27 wiz Exp $	*/
+/*	$NetBSD: gencat.c,v 1.35 2012/03/09 18:54:28 ginsbach Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: gencat.c,v 1.34 2011/12/29 22:58:27 wiz Exp $");
+__RCSID("$NetBSD: gencat.c,v 1.35 2012/03/09 18:54:28 ginsbach Exp $");
 #endif
 
 /***********************************************************
@@ -345,11 +345,13 @@ getmsg(int fd, char *cptr, char quote)
 {
 	static char *msg = NULL;
 	static size_t msglen = 0;
-	size_t    clen, i;
+	size_t  clen, i;
+	int     in_quote = 0;
 	char   *tptr;
 
 	if (quote && *cptr == quote) {
 		++cptr;
+		in_quote = 1;
 	} 
 
 	clen = strlen(cptr) + 1;
@@ -366,11 +368,26 @@ getmsg(int fd, char *cptr, char quote)
 		if (quote && *cptr == quote) {
 			char   *tmp;
 			tmp = cptr + 1;
-			if (*tmp && (!isspace((unsigned char) *tmp) || *wskip(tmp))) {
+			if (!in_quote) {
+				/* XXX hard error? */
 				warning(cptr, "unexpected quote character, ignoring");
 				*tptr++ = *cptr++;
 			} else {
-				*cptr = '\0';
+				cptr++;
+				/* don't use wskip() */
+				while (*cptr && isspace((unsigned char) *cptr))
+#ifndef _BACKWARDS_COMPAT
+					cptr++;
+#else
+					*tptr++ = *cptr++;
+#endif
+				/* XXX hard error? */
+				if (*cptr)
+					warning(tmp, "unexpected extra characters, ignoring");
+				in_quote = 0;
+#ifndef _BACKWARDS_COMPAT
+				break;
+#endif
 			}
 		} else {
 			if (*cptr == '\\') {
@@ -437,6 +454,10 @@ getmsg(int fd, char *cptr, char quote)
 			}
 		}
 	}
+
+	if (in_quote)
+		warning(cptr, "unterminated quoted message, ignoring");
+
 	*tptr = '\0';
 	return (msg);
 }

Reply via email to