Thread: Bug in convert.c copy_and_convert_field

Bug in convert.c copy_and_convert_field

From
Paul Cochrane
Date:
Hi again list.

I think I've encountered a bug in the file convert.c -
copy_and_convert_field procedure. Unfortunately my C is a little out of
practise not having done it for 10 years or so. Can anyone help? I think
I've traced the error to the default part of the switch around line 850
(that where the dodgy lines are being placed in the mylog file so it's
somewhere before that). Below is a snippet of the mylog showing the
problem. The lines where it is saying DEFAULT: & the ptr part of the
string. In some cases this is correct but in others there are lots of
extra / strange characters. The len field always seems to be correct
however.

The log file ends with a single ' which may explain the error I get on
the server (1) could not receive data from client: Connection reset by
peer and (2) unexpected EOF on client connection




]**** SC_fetch: manual_result
[2052]fetch: cols=13, lf=0, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483564
[2052]type = 1043
[2052]manual_result
[2052]value = ''
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = '',
cbValueMax=129
[2052]DEFAULT: len = 0, ptr = '8Ã3ts'
[2052]    SQL_C_CHAR, default: len = 0, cbValueMax = 129,
rgbValueBindRow = ''
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=1, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483695
[2052]type = 1043
[2052]manual_result
[2052]value = 'public'
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = 'public',
cbValueMax=129
[2052]DEFAULT: len = 6, ptr = 'public'
[2052]    SQL_C_CHAR, default: len = 6, cbValueMax = 129,
rgbValueBindRow = 'public'
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=2, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483826
[2052]type = 1043
[2052]manual_result
[2052]value = 'LOGIN'
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = 'LOGIN',
cbValueMax=129
[2052]DEFAULT: len = 5, ptr = 'LOGINc'
[2052]    SQL_C_CHAR, default: len = 5, cbValueMax = 129,
rgbValueBindRow = 'LOGIN'
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=3, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483957
[2052]type = 21
[2052]manual_result
[2052]value = '0'
[2052]copy_and_convert: field_type = 21, fctype = 5, value = '0',
cbValueMax=2
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=4, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483961
[2052]type = 1043
[2052]manual_result
[2052]value = ''
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = '',
cbValueMax=129
[2052]DEFAULT: len = 0, ptr = '8Ã3 To'
[2052]    SQL_C_CHAR, default: len = 0, cbValueMax = 129,
rgbValueBindRow = ''
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=5, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484092
[2052]type = 1043
[2052]manual_result
[2052]value = 'LOGIN_pkey'
[2052]copy_and_convert: field_type = 1043, fctype = 1, value =
'LOGIN_pkey', cbValueMax=129
[2052]DEFAULT: len = 10, ptr = 'LOGIN_pkey'
[2052]    SQL_C_CHAR, default: len = 10, cbValueMax = 129,
rgbValueBindRow = 'LOGIN_pkey'
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=6, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484223
[2052]type = 21
[2052]manual_result
[2052]value = '3'
[2052]copy_and_convert: field_type = 21, fctype = 5, value = '3',
cbValueMax=2
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=7, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484227
[2052]type = 21
[2052]manual_result
[2052]value = '1'
[2052]copy_and_convert: field_type = 21, fctype = 5, value = '1',
cbValueMax=2
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=8, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484231
[2052]type = 1043
[2052]manual_result
[2052]value = 'Login'
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = 'Login',
cbValueMax=129
[2052]DEFAULT: len = 5, ptr = 'LoginTo'
[2052]    SQL_C_CHAR, default: len = 5, cbValueMax = 129,
rgbValueBindRow = 'Login'
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=9, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484362
[2052]type = 18
[2052]manual_result
[2052]value = 'A'
[2052]copy_and_convert: field_type = 18, fctype = 1, value = 'A',
cbValueMax=2
[2052]DEFAULT: len = 1, ptr = 'AÃ3Nc'
[2052]    SQL_C_CHAR, default: len = 1, cbValueMax = 2, rgbValueBindRow
= 'A'
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=10, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484366
[2052]type = 23
[2052]manual_result
[2052]value = '<NULL>'
[2052]copy_and_convert: field_type = 23, fctype = 4, value = '<NULL>',
cbValueMax=4
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=11, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484372
[2052]type = 23
[2052]manual_result
[2052]value = '<NULL>'
[2052]copy_and_convert: field_type = 23, fctype = 4, value = '<NULL>',
cbValueMax=4
[2052]copy_and_convert: retval = 0
[2052]fetch: cols=13, lf=12, opts = 137569848, opts->bindings =
137610576, buffer[] = 35484378
[2052]type = 1043
[2052]manual_result
[2052]value = '<NULL>'
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = '<NULL>',
cbValueMax=129
[2052]copy_and_convert: retval = 0
[2052][[SQLFetch]][2052]PGAPI_ExtendedFetch: stmt=137569712
[2052]SQL_FETCH_NEXT: num_tuples=7, currtuple=0
[2052]PGAPI_ExtendedFetch: new currTuple = 0
[2052]manual_result = 1, use_declarefetch = 1
[2052]**** SC_fetch: manual_result
[2052]fetch: cols=13, lf=0, opts = 137569848, opts->bindings =
137610576, buffer[] = 35483564
[2052]type = 1043
[2052]manual_result
[2052]value = ''
[2052]copy_and_convert: field_type = 1043, fctype = 1, value = '',
cbValueMax=129
[2052]DEFAULT: len = 0, ptr = '8Ã3nTo'
[2052]    SQL_C_CHAR, default: len = 0, cbValueMax = 129,
rgbValueBindRow = ''
[2052]copy_and_convert: retval = 0

; This is how the mylog ends

[2052]copy_and_convert: field_type = 1043, fctype = 1, value =
'Classification', cbValueMax=129
[2052]DEFAULT: len = 14, ptr = '

--
  Paul Cochrane       (paul.m.cochrane@tuht.scot.nhs.uk)
+--------------------------------------------------------
| Tayside Orthopaedic & Rehabilitation Technology Centre
| Ninewells Hospital & Medical School
| Dundee, Scotland, UK.
| DD1 9SY
| Phone: Internal: 36284
|        External: +44 (1382) 496284
| Fax:   +44 (1382) 496322
+--------------------------------------------------------


Re: Bug in convert.c copy_and_convert_field

From
Paul Cochrane
Date:
Paul Cochrane wrote:

> Hi again list.
>
> I think I've encountered a bug in the file convert.c -
> copy_and_convert_field procedure. Unfortunately my C is a little out
> of practise not having done it for 10 years or so. Can anyone help? I
> think I've traced the error to the default part of the switch around
> line 850 (that where the dodgy lines are being placed in the mylog
> file so it's somewhere before that). Below is a snippet of the mylog
> showing the problem. The lines where it is saying DEFAULT: & the ptr
> part of the string. In some cases this is correct but in others there
> are lots of extra / strange characters. The len field always seems to
> be correct however.
>
> The log file ends with a single ' which may explain the error I get on
> the server (1) could not receive data from client: Connection reset by
> peer and (2) unexpected EOF on client connection
>
I've found a quick fix to this problem. I've simply added a line:

                strncpy(ptr+len, "\0", 1);

just before the mylog line on line 850 of convert.c. I believe this
simply ensures that there is a NULL at the end of the string stored in
ptr. There may be a more elegant way to do this but it seems to work.

Now onto the next fault cause it fails again shortly after this.
Bugger!  :-(

Paul

--
  Paul Cochrane       (paul.m.cochrane@tuht.scot.nhs.uk)
+--------------------------------------------------------
| Tayside Orthopaedic & Rehabilitation Technology Centre
| Ninewells Hospital & Medical School
| Dundee, Scotland, UK.
| DD1 9SY
| Phone: Internal: 36284
|        External: +44 (1382) 496284
| Fax:   +44 (1382) 496322
+--------------------------------------------------------


Re: Bug in convert.c copy_and_convert_field

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Paul Cochrane
> Sent: 11 February 2005 18:06
> To: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Bug in convert.c copy_and_convert_field
>
> I've found a quick fix to this problem. I've simply added a line:
>
>                 strncpy(ptr+len, "\0", 1);
>
> just before the mylog line on line 850 of convert.c. I believe this
> simply ensures that there is a NULL at the end of the string
> stored in
> ptr. There may be a more elegant way to do this but it seems to work.

I don't know if this fix is correct or not, but are you sure that ptr is
big enough to do this without clobbering something else?

Regards, Dave.

Re: Bug in convert.c copy_and_convert_field

From
Paul Cochrane
Date:
Dave Page wrote:

>
>
>>Subject: Re: [ODBC] Bug in convert.c copy_and_convert_field
>>
>>I've found a quick fix to this problem. I've simply added a line:
>>
>>                strncpy(ptr+len, "\0", 1);
>>
>>just before the mylog line on line 850 of convert.c. I believe this
>>simply ensures that there is a NULL at the end of the string
>>stored in
>>ptr. There may be a more elegant way to do this but it seems to work.
>>
>>
>
>I don't know if this fix is correct or not, but are you sure that ptr is
>big enough to do this without clobbering something else?
>
>Regards, Dave.
>
>
To be honest, I'm not entirely sure. I'm guessing that it's OK since the
returned LEN vaule seems to be set correctly. The mylog just returns
rubbish as the string value which I took to be related to not having a
NULL at the end of the string.

Paul

--
  Paul Cochrane       (paul.m.cochrane@tuht.scot.nhs.uk)
+--------------------------------------------------------
| Tayside Orthopaedic & Rehabilitation Technology Centre
| Ninewells Hospital & Medical School
| Dundee, Scotland, UK.
| DD1 9SY
| Phone: Internal: 36284
|        External: +44 (1382) 496284
| Fax:   +44 (1382) 496322
+--------------------------------------------------------