From: Howard Chu Date: Fri, 9 Sep 2011 06:41:06 +0000 (-0700) Subject: Add a few NULL checks to defend against dumb API checkers. X-Git-Tag: OPENLDAP_REL_ENG_2_4_27~249 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fafc899129e290a79040e1b3287b0559b70354c0;p=openldap Add a few NULL checks to defend against dumb API checkers. Unfortunately automated checkers don't seem to read the documentation for how APIs are expected to be used, and the C declaration syntax isn't expressive enough to encode the documented usage. --- diff --git a/libraries/libldap/schema.c b/libraries/libldap/schema.c index 000176ab38..0121139820 100644 --- a/libraries/libldap/schema.c +++ b/libraries/libldap/schema.c @@ -41,48 +41,56 @@ choose_name( char *names[], const char *fallback ) LDAP_CONST char * ldap_syntax2name( LDAPSyntax * syn ) { + if (!syn) return NULL; return( syn->syn_oid ); } LDAP_CONST char * ldap_matchingrule2name( LDAPMatchingRule * mr ) { + if (!mr) return NULL; return( choose_name( mr->mr_names, mr->mr_oid ) ); } LDAP_CONST char * ldap_matchingruleuse2name( LDAPMatchingRuleUse * mru ) { + if (!mru) return NULL; return( choose_name( mru->mru_names, mru->mru_oid ) ); } LDAP_CONST char * ldap_attributetype2name( LDAPAttributeType * at ) { + if (!at) return NULL; return( choose_name( at->at_names, at->at_oid ) ); } LDAP_CONST char * ldap_objectclass2name( LDAPObjectClass * oc ) { + if (!oc) return NULL; return( choose_name( oc->oc_names, oc->oc_oid ) ); } LDAP_CONST char * ldap_contentrule2name( LDAPContentRule * cr ) { + if (!cr) return NULL; return( choose_name( cr->cr_names, cr->cr_oid ) ); } LDAP_CONST char * ldap_nameform2name( LDAPNameForm * nf ) { + if (!nf) return NULL; return( choose_name( nf->nf_names, nf->nf_oid ) ); } LDAP_CONST char * ldap_structurerule2name( LDAPStructureRule * sr ) { + if (!sr) return NULL; return( choose_name( sr->sr_names, NULL ) ); } @@ -379,7 +387,10 @@ struct berval * ldap_syntax2bv( LDAPSyntax * syn, struct berval *bv ) { safe_string * ss; - + + if ( !syn || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -421,7 +432,10 @@ struct berval * ldap_matchingrule2bv( LDAPMatchingRule * mr, struct berval *bv ) { safe_string * ss; - + + if ( !mr || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -480,7 +494,10 @@ struct berval * ldap_matchingruleuse2bv( LDAPMatchingRuleUse * mru, struct berval *bv ) { safe_string * ss; - + + if ( !mru || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -539,7 +556,10 @@ struct berval * ldap_objectclass2bv( LDAPObjectClass * oc, struct berval *bv ) { safe_string * ss; - + + if ( !oc || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -628,7 +648,10 @@ struct berval * ldap_contentrule2bv( LDAPContentRule * cr, struct berval *bv ) { safe_string * ss; - + + if ( !cr || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -707,7 +730,10 @@ struct berval * ldap_structurerule2bv( LDAPStructureRule * sr, struct berval *bv ) { safe_string * ss; - + + if ( !sr || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -771,7 +797,10 @@ struct berval * ldap_nameform2bv( LDAPNameForm * nf, struct berval *bv ) { safe_string * ss; - + + if ( !nf || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -840,7 +869,10 @@ struct berval * ldap_attributetype2bv( LDAPAttributeType * at, struct berval *bv ) { safe_string * ss; - + + if ( !at || !bv ) + return NULL; + ss = new_safe_string(256); if ( !ss ) return NULL; @@ -1455,6 +1487,7 @@ free_extensions(LDAPSchemaExtensionItem **extensions) void ldap_syntax_free( LDAPSyntax * syn ) { + if ( !syn ) return; LDAP_FREE(syn->syn_oid); if (syn->syn_names) LDAP_VFREE(syn->syn_names); if (syn->syn_desc) LDAP_FREE(syn->syn_desc); @@ -1596,6 +1629,7 @@ ldap_str2syntax( LDAP_CONST char * s, void ldap_matchingrule_free( LDAPMatchingRule * mr ) { + if (!mr) return; LDAP_FREE(mr->mr_oid); if (mr->mr_names) LDAP_VFREE(mr->mr_names); if (mr->mr_desc) LDAP_FREE(mr->mr_desc); @@ -1795,6 +1829,7 @@ ldap_str2matchingrule( LDAP_CONST char * s, void ldap_matchingruleuse_free( LDAPMatchingRuleUse * mru ) { + if (!mru) return; LDAP_FREE(mru->mru_oid); if (mru->mru_names) LDAP_VFREE(mru->mru_names); if (mru->mru_desc) LDAP_FREE(mru->mru_desc); @@ -1993,6 +2028,7 @@ ldap_str2matchingruleuse( LDAP_CONST char * s, void ldap_attributetype_free(LDAPAttributeType * at) { + if (!at) return; LDAP_FREE(at->at_oid); if (at->at_names) LDAP_VFREE(at->at_names); if (at->at_desc) LDAP_FREE(at->at_desc); @@ -2376,6 +2412,7 @@ ldap_str2attributetype( LDAP_CONST char * s, void ldap_objectclass_free(LDAPObjectClass * oc) { + if (!oc) return; LDAP_FREE(oc->oc_oid); if (oc->oc_names) LDAP_VFREE(oc->oc_names); if (oc->oc_desc) LDAP_FREE(oc->oc_desc); @@ -2662,6 +2699,7 @@ ldap_str2objectclass( LDAP_CONST char * s, void ldap_contentrule_free(LDAPContentRule * cr) { + if (!cr) return; LDAP_FREE(cr->cr_oid); if (cr->cr_names) LDAP_VFREE(cr->cr_names); if (cr->cr_desc) LDAP_FREE(cr->cr_desc); @@ -2919,6 +2957,7 @@ ldap_str2contentrule( LDAP_CONST char * s, void ldap_structurerule_free(LDAPStructureRule * sr) { + if (!sr) return; if (sr->sr_names) LDAP_VFREE(sr->sr_names); if (sr->sr_desc) LDAP_FREE(sr->sr_desc); if (sr->sr_nameform) LDAP_FREE(sr->sr_nameform); @@ -3101,6 +3140,7 @@ ldap_str2structurerule( LDAP_CONST char * s, void ldap_nameform_free(LDAPNameForm * nf) { + if (!nf) return; LDAP_FREE(nf->nf_oid); if (nf->nf_names) LDAP_VFREE(nf->nf_names); if (nf->nf_desc) LDAP_FREE(nf->nf_desc); diff --git a/libraries/libldap/tls2.c b/libraries/libldap/tls2.c index 13a9a99d1d..a7c67686c0 100644 --- a/libraries/libldap/tls2.c +++ b/libraries/libldap/tls2.c @@ -807,10 +807,14 @@ ldap_pvt_tls_set_option( LDAP *ld, int option, void *arg ) int ldap_int_tls_start ( LDAP *ld, LDAPConn *conn, LDAPURLDesc *srv ) { - Sockbuf *sb = conn->lconn_sb; + Sockbuf *sb; char *host; void *ssl; + if ( !conn ) + return LDAP_PARAM_ERROR; + + sb = conn->lconn_sb; if( srv ) { host = srv->lud_host; } else {