Partial fix for 148272 - flawfinder warnings in directory.
Fix most critical warnings in the core LDAP library code:
AIX has snprintf() so we now #define HAVE_SNPRINTF there.
Use snprintf() instead of sprintf() in ldap_perror().
Use snprintf() instead of sprintf() in ldap_init_getfilter_buf()
and improve error reporting for bad regular expressions.
git-svn-id: svn://10.0.0.236/trunk@140507 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -145,7 +145,7 @@
|
||||
* Is snprintf() part of the standard C runtime library?
|
||||
*/
|
||||
#if !defined(HAVE_SNPRINTF)
|
||||
#if defined(SOLARIS) || defined(LINUX) || defined(HPUX)
|
||||
#if defined(SOLARIS) || defined(LINUX) || defined(HPUX) || defined(AIX)
|
||||
#define HAVE_SNPRINTF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -143,7 +143,12 @@ ldap_perror( LDAP *ld, const char *s )
|
||||
}
|
||||
|
||||
if ( ld == NULL ) {
|
||||
sprintf( msg, "%s%s%s", s, separator,
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"%s%s%s", s, separator,
|
||||
nsldapi_safe_strerror( errno ) );
|
||||
ber_err_print( msg );
|
||||
return;
|
||||
@@ -153,8 +158,13 @@ ldap_perror( LDAP *ld, const char *s )
|
||||
err = LDAP_GET_LDERRNO( ld, &matched, &errmsg );
|
||||
for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) {
|
||||
if ( err == ldap_errlist[i].e_code ) {
|
||||
sprintf( msg, "%s%s%s", s, separator,
|
||||
ldap_errlist[i].e_reason );
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"%s%s%s", s, separator,
|
||||
ldap_errlist[i].e_reason );
|
||||
ber_err_print( msg );
|
||||
if ( err == LDAP_CONNECT_ERROR ) {
|
||||
ber_err_print( " - " );
|
||||
@@ -163,12 +173,22 @@ ldap_perror( LDAP *ld, const char *s )
|
||||
}
|
||||
ber_err_print( "\n" );
|
||||
if ( matched != NULL && *matched != '\0' ) {
|
||||
sprintf( msg, "%s%smatched: %s\n",
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"%s%smatched: %s\n",
|
||||
s, separator, matched );
|
||||
ber_err_print( msg );
|
||||
}
|
||||
if ( errmsg != NULL && *errmsg != '\0' ) {
|
||||
sprintf( msg, "%s%sadditional info: %s\n",
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"%s%sadditional info: %s\n",
|
||||
s, separator, errmsg );
|
||||
ber_err_print( msg );
|
||||
}
|
||||
@@ -176,7 +196,12 @@ ldap_perror( LDAP *ld, const char *s )
|
||||
return;
|
||||
}
|
||||
}
|
||||
sprintf( msg, "%s%sNot an LDAP errno %d\n", s, separator, err );
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"%s%sNot an LDAP errno %d\n", s, separator, err );
|
||||
ber_err_print( msg );
|
||||
LDAP_MUTEX_UNLOCK( ld, LDAP_ERR_LOCK );
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of
|
||||
|
||||
#include "ldap-int.h"
|
||||
#include "regex.h"
|
||||
#include <stdio.h> /* sprintf */
|
||||
|
||||
static int break_into_words( char *str, char *delims, char ***wordsp );
|
||||
int nsldapi_next_line_tokens( char **bufp, long *blenp, char ***toksp );
|
||||
@@ -102,7 +101,7 @@ ldap_init_getfilter_buf( char *buf, long buflen )
|
||||
LDAPFiltDesc *lfdp;
|
||||
LDAPFiltList *flp, *nextflp;
|
||||
LDAPFiltInfo *fip, *nextfip;
|
||||
char *tag, **tok;
|
||||
char *errmsg, *tag, **tok;
|
||||
int tokcnt, i;
|
||||
|
||||
if ( (buf == NULL) || (buflen < 0) ||
|
||||
@@ -134,11 +133,16 @@ ldap_init_getfilter_buf( char *buf, long buflen )
|
||||
}
|
||||
nextflp->lfl_tag = nsldapi_strdup( tag );
|
||||
nextflp->lfl_pattern = tok[ 0 ];
|
||||
if ( re_comp( nextflp->lfl_pattern ) != NULL ) {
|
||||
char msg[256];
|
||||
if (( errmsg = re_comp( nextflp->lfl_pattern )) != NULL ) {
|
||||
char msg[512];
|
||||
ldap_getfilter_free( lfdp );
|
||||
sprintf( msg, "bad regular expresssion %s\n",
|
||||
nextflp->lfl_pattern );
|
||||
#ifdef HAVE_SNPRINTF
|
||||
snprintf( msg, sizeof(msg),
|
||||
#else
|
||||
sprintf( msg,
|
||||
#endif
|
||||
"bad regular expression \"%s\" - %s\n",
|
||||
nextflp->lfl_pattern, errmsg );
|
||||
ber_err_print( msg );
|
||||
nsldapi_free_strarray( tok );
|
||||
return( NULL );
|
||||
|
||||
Reference in New Issue
Block a user