Re: ldapd: avoid passing NULL to asprintf(3) when there's no parent dn entry

2018-06-25 Thread Gleydson Soares
On Mon, Jun 25, 2018 at 12:27:23PM +0200, Jeremie Courreges-Anglas wrote:
> On Mon, Jun 25 2018, Gleydson Soares  wrote:
> > avoid passing NULL to asprintf(3) when there's no parent dn entry,
> > this happens when adding a new naming context and then putting the first
> > rdn in.
> >
> > Jun 24 23:51:23 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"
> > Jun 25 00:13:14 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"
> 
> Are those log entries the only symptom, or does this problem affect
> ldapd(8) operations?

it doesn't affect anything, just messed up my logs.

> 
> The diff looks correct but more complicated than necessary.  Unless I'm
> missing something the shorter diff below would also help.  Does it work
> for you?

clever!
works for me, i'm going to commit it tonight. thanks,

> 
> 
> Index: index.c
> ===
> RCS file: /d/cvs/src/usr.sbin/ldapd/index.c,v
> retrieving revision 1.11
> diff -u -p -p -u -r1.11 index.c
> --- index.c   20 Jan 2017 11:55:08 -  1.11
> +++ index.c   25 Jun 2018 10:19:00 -
> @@ -138,6 +138,7 @@ index_rdn_key(struct namespace *ns, stru
>   if (parent_dn == NULL) {
>   rdnsz = dnsz;
>   pdnsz = 0;
> + parent_dn = "";
>   } else {
>   rdnsz = parent_dn - (char *)dn->data;
>   pdnsz = dnsz - rdnsz - 1;
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: ldapd: avoid passing NULL to asprintf(3) when there's no parent dn entry

2018-06-25 Thread Jeremie Courreges-Anglas
On Mon, Jun 25 2018, Gleydson Soares  wrote:
> avoid passing NULL to asprintf(3) when there's no parent dn entry,
> this happens when adding a new naming context and then putting the first
> rdn in.
>
> Jun 24 23:51:23 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"
> Jun 25 00:13:14 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"

Are those log entries the only symptom, or does this problem affect
ldapd(8) operations?

The diff looks correct but more complicated than necessary.  Unless I'm
missing something the shorter diff below would also help.  Does it work
for you?


Index: index.c
===
RCS file: /d/cvs/src/usr.sbin/ldapd/index.c,v
retrieving revision 1.11
diff -u -p -p -u -r1.11 index.c
--- index.c 20 Jan 2017 11:55:08 -  1.11
+++ index.c 25 Jun 2018 10:19:00 -
@@ -138,6 +138,7 @@ index_rdn_key(struct namespace *ns, stru
if (parent_dn == NULL) {
rdnsz = dnsz;
pdnsz = 0;
+   parent_dn = "";
} else {
rdnsz = parent_dn - (char *)dn->data;
pdnsz = dnsz - rdnsz - 1;

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



ldapd: avoid passing NULL to asprintf(3) when there's no parent dn entry

2018-06-24 Thread Gleydson Soares
avoid passing NULL to asprintf(3) when there's no parent dn entry,
this happens when adding a new naming context and then putting the first
rdn in.

Jun 24 23:51:23 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"
Jun 25 00:13:14 x250 ldapd: vfprintf %s NULL in "@%.*s,%.*s"

? ldapd.diff
Index: index.c
===
RCS file: /cvs/src/usr.sbin/ldapd/index.c,v
retrieving revision 1.11
diff -u -p -r1.11 index.c
--- index.c 20 Jan 2017 11:55:08 -  1.11
+++ index.c 24 Jun 2018 22:06:04 -
@@ -144,9 +144,14 @@ index_rdn_key(struct namespace *ns, stru
++parent_dn;
}
 
-   if (asprintf(&t, "@%.*s,%.*s", pdnsz, parent_dn, rdnsz,
-   (char *)dn->data) == -1)
-   return -1;
+   if (!pdnsz) {
+   if (asprintf(&t, "@,%.*s", rdnsz, (char *)dn->data) == -1)
+   return -1;
+   } else {
+   if (asprintf(&t, "@%.*s,%.*s", pdnsz, parent_dn, rdnsz,
+   (char *)dn->data) == -1)
+   return -1;
+   }
 
normalize_dn(t);
key->data = t;