From: Mike Taylor Date: Wed, 5 Apr 2006 12:04:51 +0000 (+0000) Subject: Report SRU diagnostic 12 (too many chars in query) when rendering the X-Git-Tag: YAZ.2.1.18~41 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=e9db3cf52b6df66badd97391a51e85f9c78a8c91;p=yaz-moved-to-github.git Report SRU diagnostic 12 (too many chars in query) when rendering the compiled CQL query out into PQF tries to overrun the supplied buffer. Fixes a bug that was mystifying while we put the Alvis demo together. --- diff --git a/src/cqltransform.c b/src/cqltransform.c index 74ad961..8494046 100644 --- a/src/cqltransform.c +++ b/src/cqltransform.c @@ -1,4 +1,4 @@ -/* $Id: cqltransform.c,v 1.21 2006-03-20 14:56:40 mike Exp $ +/* $Id: cqltransform.c,v 1.22 2006-04-05 12:04:51 mike Exp $ Copyright (C) 1995-2005, Index Data ApS Index Data Aps @@ -16,6 +16,7 @@ See the file LICENSE. #include #include #include +#include struct cql_prop_entry { char *pattern; @@ -596,6 +597,16 @@ int cql_transform_buf(cql_transform_t ct, struct cql_node *cn, info.max = max; info.buf = out; r = cql_transform(ct, cn, cql_buf_write_handler, &info); + if (info.off < 0) { + /* Attempt to write past end of buffer. For some reason, this + SRW diagnostic is deprecated, but it's so perfect for our + purposes that it would be stupid not to use it. */ + char numbuf[30]; + ct->error = YAZ_SRW_TOO_MANY_CHARS_IN_QUERY; + sprintf(numbuf, "%ld", (long) info.max); + ct->addinfo = xstrdup(numbuf); + return -1; + } if (info.off >= 0) info.buf[info.off] = '\0'; return r;