Issue 7248 - Cast to string in back-sql when upper_needs_cast is declared in slapd.conf
Summary: Cast to string in back-sql when upper_needs_cast is declared in slapd.conf
Status: VERIFIED SUSPENDED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: backends (show other issues)
Version: 2.4.30
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-17 07:48 UTC by rene.snajder@i-med.ac.at
Modified: 2021-04-01 16:27 UTC (History)
0 users

See Also:


Attachments
openldap-upper-strcast.patch (970 bytes, patch)
2020-03-20 14:14 UTC, Quanah Gibson-Mount
Details

Note You need to log in before you can comment on or make changes to this issue.
Description rene.snajder@i-med.ac.at 2012-04-17 07:48:50 UTC
Full_Name: Rene Snajder
Version: 2.4.30
OS: RHEL 6
URL: ftp://ftp.openldap.org/incoming/openldap-upper-strcast.patch
Submission from: (NULL) (193.171.77.1)


I reported (from my other e-mail address dermaniac@gmail.com) a bug report in
January. I reported it to the technical mailing list first:
http://www.openldap.org/lists/openldap-technical/201201/msg00233.html
which I got no reply on. I then posted a ticket here:
http://www.openldap.org/its/index.cgi/Incoming?id=7130;page=12
which I got one reply but it didn't fix my problem (and I didn't get further
replies).

I then took matters in my own hand and found 3 bugs in back-sql which lead to
errors when UPPER is applied to integer values.

Since there was no reaction here I tried to report it to Redhat (since I'm using
RHEL) where the issue finally got some attention. I created a bugfix and they
advised me to submit it directly to openldap, so now I'm trying it here again.

Strangely, the same day that redhat responded to my patch I got a reply here:
http://www.openldap.org/lists/openldap-technical/201204/msg00108.html
to which I cannot seem to answer (my mails to the mailing list never seem to
make it through).

Here are the bugs that I found:

1) It is not checked whether the UPPER function can be applied on a type in the
database. Comments in the code itself confirm that this is "currently broken".
(see my previous 2 comments)

2) One would assume that the parameter "upper_needs_cast yes" in the slapd.conf
would add a string casting statement to every UPPER statement in the SQL
queries. In fact, it only does so for one single query (when it queries for
"ldap_entries.dn"). All other queries where UPPER is applied still don't use a
cast, even though I declare "upper_needs_cast yes" in the main config file.

3) The slapd.conf file lets me declare a "strcast_func" which is the name of
the function for a cast to string.  This strcast_func is used at some points in
the queries, but not consistently. For the one query that actually pays any
attention to the "upper_needs_cast" parameter (which i mentioned before) a
hardcoded string cast function is used instead. This function is always "(cast
? as varchar(255))". 

Now these are 3 separate problems in the back-sql code. To fix my particular
problem I took a closer look at problem number 2. I
attached an patch which can be applied to the version in the GIT repository.
When
this patch is applied, the hardcoded strcast function from problem number 3 is
at least applied to every use of the UPPER function (or at least everywhere
where the upper function is applied properly!), effectively fixing problem
number 2.

This may THEORETICALLY lead to the following problem:
IF someone set "upper_needs_cast yes" in their config, with a database backend
that does not support the hardcoded strcast function, this patch would break
the SQL queries for this user. BUT, in that case using the "upper_needs_cast
yes" statement would have been useless - or even causing problems - before this
patch anyways - since it was always using the hardcoded function and only at
one single point.

My patch is here:
ftp://ftp.openldap.org/incoming/openldap-upper-strcast.patch

For a more detailed description see my bug report in the Redhat Bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=809105
Comment 1 rene.snajder@i-med.ac.at 2012-04-17 07:55:09 UTC
Oh, and I forgot:

The attached modifications to OpenLDAP Software are subject to the 
following notice:
Copyright 2012 Rene Snajder
Redistribution and use in source and binary forms, with or without 
modification, are permitted only as authorized by the OpenLDAP Public 
License.

Comment 2 rene.snajder@i-med.ac.at 2012-05-21 10:46:21 UTC
Dear OpenLDAP Devs,

I would like to ask if there is anything else I can do to speed up the 
inclusion of my patch?

Comment 3 OpenLDAP project 2017-04-12 21:03:50 UTC
fixes 3 bugs in back-sql
patch provided
Comment 4 Quanah Gibson-Mount 2017-04-12 21:03:50 UTC
changed notes
moved from Incoming to Software Bugs
Comment 5 Quanah Gibson-Mount 2020-03-20 14:14:59 UTC
Created attachment 624 [details]
openldap-upper-strcast.patch