Skip to content

Commit 461db2d

Browse files
committed
ITS#7497 fix lineno overflow in ldif_read_record()
1 parent 8325ad2 commit 461db2d

File tree

12 files changed

+56
-54
lines changed

12 files changed

+56
-54
lines changed

clients/tools/ldapmodify.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int ldapadd;
7373
static char *rejfile = NULL;
7474
static LDAP *ld = NULL;
7575

76-
static int process_ldif_rec LDAP_P(( char *rbuf, int lineno ));
76+
static int process_ldif_rec LDAP_P(( char *rbuf, unsigned long lineno ));
7777
static int domodify LDAP_P((
7878
const struct berval *dn,
7979
LDAPMod **pmods,
@@ -220,8 +220,8 @@ main( int argc, char **argv )
220220
char *matched_msg, *error_msg;
221221
int rc, retval, ldifrc;
222222
int len;
223-
int i = 0;
224-
int lineno, nextline = 0, lmax = 0;
223+
int i = 0, lmax = 0;
224+
unsigned long lineno, nextline = 0;
225225
LDAPControl c[1];
226226

227227
prog = lutil_progname( "ldapmodify", argc, argv );
@@ -377,7 +377,7 @@ fail:;
377377

378378

379379
static int
380-
process_ldif_rec( char *rbuf, int linenum )
380+
process_ldif_rec( char *rbuf, unsigned long linenum )
381381
{
382382
LDIFRecord lr;
383383
int lrflags = ldapadd ? LDIF_DEFAULT_ADD : 0;

include/ldap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ ldap_ldif_record_done LDAP_P((
26632663
LDAP_F( int )
26642664
ldap_parse_ldif_record LDAP_P((
26652665
struct berval *rbuf,
2666-
int linenum,
2666+
unsigned long linenum,
26672667
LDIFRecord *lr,
26682668
const char *errstr,
26692669
unsigned int flags ));

include/ldap_pvt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ LDAP_F ( int ) ldap_pvt_discard LDAP_P((
323323
LDAP_F( int )
324324
ldap_parse_ldif_record_x LDAP_P((
325325
struct berval *rbuf,
326-
int linenum,
326+
unsigned long linenum,
327327
struct ldifrecord *lr,
328328
const char *errstr,
329329
unsigned int flags,

include/ldif.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ldif_close LDAP_P(( LDIFFP * ));
105105
LDAP_LDIF_F( int )
106106
ldif_read_record LDAP_P((
107107
LDIFFP *fp,
108-
int *lineno,
108+
unsigned long *lineno,
109109
char **bufp,
110110
int *buflen ));
111111

libraries/libldap/ldif.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ ldif_close(
814814
int
815815
ldif_read_record(
816816
LDIFFP *lfp,
817-
int *lno, /* ptr to line number counter */
817+
unsigned long *lno, /* ptr to line number counter */
818818
char **bufp, /* ptr to malloced output buffer */
819819
int *buflenp ) /* ptr to length of *bufp */
820820
{

libraries/libldap/ldifutil.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ldap_ldif_record_done( LDIFRecord *lr )
100100
int
101101
ldap_parse_ldif_record_x(
102102
struct berval *rbuf,
103-
int linenum,
103+
unsigned long linenum,
104104
LDIFRecord *lr,
105105
const char *errstr,
106106
unsigned int flags,
@@ -155,7 +155,7 @@ ldap_parse_ldif_record_x(
155155
}
156156

157157
if ( ( rc = ldif_parse_line2( line, lr->lr_btype+i, lr->lr_vals+i, &freev ) ) < 0 ) {
158-
fprintf( stderr, _("%s: invalid format (line %d) entry: \"%s\"\n"),
158+
fprintf( stderr, _("%s: invalid format (line %lu) entry: \"%s\"\n"),
159159
errstr, linenum+i, dn == NULL ? "" : dn );
160160
rc = LDAP_PARAM_ERROR;
161161
goto leave;
@@ -175,7 +175,7 @@ ldap_parse_ldif_record_x(
175175
if ( lr->lr_vals[i].bv_len != version1.bv_len || strncmp( lr->lr_vals[i].bv_val, version1.bv_val, version1.bv_len ) != 0 )
176176
{
177177
fprintf( stderr,
178-
_("%s: invalid version %s, line %d (ignored)\n"),
178+
_("%s: invalid version %s, line %lu (ignored)\n"),
179179
errstr, lr->lr_vals[i].bv_val, linenum );
180180
}
181181
version++;
@@ -215,15 +215,15 @@ ldap_parse_ldif_record_x(
215215
rc = parse_ldif_control( lr->lr_vals+i, &pctrls );
216216
if (rc != 0) {
217217
fprintf( stderr,
218-
_("%s: Error processing %s line, line %d: %s\n"),
218+
_("%s: Error processing %s line, line %lu: %s\n"),
219219
errstr, BV_CONTROL.bv_val, linenum+i, ldap_err2string(rc) );
220220
}
221221
}
222222
i++;
223223
if ( i>= lr->lr_lines ) {
224224
short_input:
225225
fprintf( stderr,
226-
_("%s: Expecting more input after %s line, line %d\n"),
226+
_("%s: Expecting more input after %s line, line %lu\n"),
227227
errstr, lr->lr_btype[i-1].bv_val, linenum+i );
228228

229229
rc = LDAP_PARAM_ERROR;
@@ -244,7 +244,7 @@ ldap_parse_ldif_record_x(
244244

245245
if ( ++icnt != lr->lr_vals[i].bv_len ) {
246246
fprintf( stderr, _("%s: illegal trailing space after"
247-
" \"%s: %s\" trimmed (line %d, entry \"%s\")\n"),
247+
" \"%s: %s\" trimmed (line %lu, entry \"%s\")\n"),
248248
errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
249249
lr->lr_vals[i].bv_val[icnt] = '\0';
250250
}
@@ -255,7 +255,7 @@ ldap_parse_ldif_record_x(
255255
if ( flags & LDIF_ENTRIES_ONLY ) {
256256
if ( !( BV_CASEMATCH( lr->lr_vals+i, &BV_ADDCT )) ) {
257257
ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
258-
_("%s: skipping LDIF record beginning at line %d: "
258+
_("%s: skipping LDIF record beginning at line %lu: "
259259
"changetype '%.*s' found but entries only was requested\n"),
260260
errstr, linenum,
261261
(int)lr->lr_vals[i].bv_len,
@@ -279,7 +279,7 @@ ldap_parse_ldif_record_x(
279279
goto short_input;
280280
if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWRDN )) {
281281
fprintf( stderr, _("%s: expecting \"%s:\" but saw"
282-
" \"%s:\" (line %d, entry \"%s\")\n"),
282+
" \"%s:\" (line %lu, entry \"%s\")\n"),
283283
errstr, BV_NEWRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
284284
rc = LDAP_PARAM_ERROR;
285285
goto leave;
@@ -290,7 +290,7 @@ ldap_parse_ldif_record_x(
290290
goto short_input;
291291
if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_DELETEOLDRDN )) {
292292
fprintf( stderr, _("%s: expecting \"%s:\" but saw"
293-
" \"%s:\" (line %d, entry \"%s\")\n"),
293+
" \"%s:\" (line %lu, entry \"%s\")\n"),
294294
errstr, BV_DELETEOLDRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
295295
rc = LDAP_PARAM_ERROR;
296296
goto leave;
@@ -300,7 +300,7 @@ ldap_parse_ldif_record_x(
300300
if ( i < lr->lr_lines ) {
301301
if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWSUP )) {
302302
fprintf( stderr, _("%s: expecting \"%s:\" but saw"
303-
" \"%s:\" (line %d, entry \"%s\")\n"),
303+
" \"%s:\" (line %lu, entry \"%s\")\n"),
304304
errstr, BV_NEWSUP.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
305305
rc = LDAP_PARAM_ERROR;
306306
goto leave;
@@ -313,7 +313,7 @@ ldap_parse_ldif_record_x(
313313
got_all = delete_entry = 1;
314314
} else {
315315
fprintf( stderr,
316-
_("%s: unknown %s \"%s\" (line %d, entry \"%s\")\n"),
316+
_("%s: unknown %s \"%s\" (line %lu, entry \"%s\")\n"),
317317
errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
318318
rc = LDAP_PARAM_ERROR;
319319
goto leave;
@@ -327,7 +327,7 @@ ldap_parse_ldif_record_x(
327327
there must be no changetype, and the flag LDIF_DEFAULT_ADD must be set */
328328
if ( flags & LDIF_ENTRIES_ONLY ) {
329329
ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
330-
_("%s: skipping LDIF record beginning at line %d: "
330+
_("%s: skipping LDIF record beginning at line %lu: "
331331
"no changetype found but entries only was requested and "
332332
"the default setting for missing changetype is modify\n"),
333333
errstr, linenum );
@@ -339,7 +339,7 @@ ldap_parse_ldif_record_x(
339339
if ( got_all ) {
340340
if ( i < lr->lr_lines ) {
341341
fprintf( stderr,
342-
_("%s: extra lines at end (line %d, entry \"%s\")\n"),
342+
_("%s: extra lines at end (line %lu, entry \"%s\")\n"),
343343
errstr, linenum+i, dn );
344344
rc = LDAP_PARAM_ERROR;
345345
goto leave;
@@ -358,7 +358,7 @@ ldap_parse_ldif_record_x(
358358
for (j=i+1; j<lr->lr_lines; j++) {
359359
if ( !lr->lr_btype[j].bv_val ) {
360360
fprintf( stderr,
361-
_("%s: missing attributeDescription (line %d, entry \"%s\")\n"),
361+
_("%s: missing attributeDescription (line %lu, entry \"%s\")\n"),
362362
errstr, linenum+j, dn );
363363
rc = LDAP_PARAM_ERROR;
364364
goto leave;
@@ -400,7 +400,7 @@ ldap_parse_ldif_record_x(
400400
if ( BV_CASEMATCH( lr->lr_btype+i, &BV_DN )) {
401401
fprintf( stderr, _("%s: attributeDescription \"%s\":"
402402
" (possible missing newline"
403-
" after line %d, entry \"%s\"?)\n"),
403+
" after line %lu, entry \"%s\"?)\n"),
404404
errstr, lr->lr_btype[i].bv_val, linenum+i - 1, dn );
405405
}
406406
if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
@@ -434,7 +434,7 @@ ldap_parse_ldif_record_x(
434434

435435
if ( ++icnt != lr->lr_vals[i].bv_len ) {
436436
fprintf( stderr, _("%s: illegal trailing space after"
437-
" \"%s: %s\" trimmed (line %d, entry \"%s\")\n"),
437+
" \"%s: %s\" trimmed (line %lu, entry \"%s\")\n"),
438438
errstr, type, lr->lr_vals[i].bv_val, linenum+i, dn );
439439
lr->lr_vals[i].bv_val[icnt] = '\0';
440440
}
@@ -465,7 +465,7 @@ ldap_parse_ldif_record_x(
465465
nmods--;
466466
} else { /* no modify op: invalid LDIF */
467467
fprintf( stderr, _("%s: modify operation type is missing at"
468-
" line %d, entry \"%s\"\n"),
468+
" line %lu, entry \"%s\"\n"),
469469
errstr, linenum+i, dn );
470470
rc = LDAP_PARAM_ERROR;
471471
goto leave;
@@ -479,7 +479,7 @@ ldap_parse_ldif_record_x(
479479
} else {
480480
if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
481481
fprintf( stderr, _("%s: wrong attributeType at"
482-
" line %d, entry \"%s\"\n"),
482+
" line %lu, entry \"%s\"\n"),
483483
errstr, linenum+i, dn );
484484
rc = LDAP_PARAM_ERROR;
485485
goto leave;
@@ -564,7 +564,7 @@ ldap_parse_ldif_record_x(
564564
int
565565
ldap_parse_ldif_record(
566566
struct berval *rbuf,
567-
int linenum,
567+
unsigned long linenum,
568568
LDIFRecord *lr,
569569
const char *errstr,
570570
unsigned int flags )

servers/slapd/back-sql/config.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ read_baseObject(
539539
{
540540
backsql_info *bi = (backsql_info *)be->be_private;
541541
LDIFFP *fp;
542-
int rc = 0, lineno = 0, lmax = 0, ldifrc;
542+
int rc = 0, lmax = 0, ldifrc;
543+
unsigned long lineno = 0;
543544
char *buf = NULL;
544545

545546
assert( fname != NULL );
@@ -571,7 +572,7 @@ read_baseObject(
571572

572573
if( e == NULL ) {
573574
fprintf( stderr, "back-sql baseObject: "
574-
"could not parse entry (line=%d)\n",
575+
"could not parse entry (line=%lu)\n",
575576
lineno );
576577
rc = LDAP_OTHER;
577578
break;
@@ -581,7 +582,7 @@ read_baseObject(
581582
if ( !be_issuffix( be, &e->e_nname ) ) {
582583
fprintf( stderr,
583584
"back-sql: invalid baseObject - "
584-
"dn=\"%s\" (line=%d)\n",
585+
"dn=\"%s\" (line=%lu)\n",
585586
e->e_name.bv_val, lineno );
586587
entry_free( e );
587588
rc = LDAP_OTHER;

servers/slapd/root_dse.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ int
401401
root_dse_read_file( const char *fname )
402402
{
403403
struct LDIFFP *fp;
404-
int rc = 0, lineno = 0, lmax = 0, ldifrc;
404+
int rc = 0, lmax = 0, ldifrc;
405+
unsigned long lineno = 0;
405406
char *buf = NULL;
406407

407408
if ( (fp = ldif_open( fname, "r" )) == NULL ) {
@@ -427,7 +428,7 @@ root_dse_read_file( const char *fname )
427428

428429
if( e == NULL ) {
429430
Debug( LDAP_DEBUG_ANY, "root_dse_read_file: "
430-
"could not parse entry (file=\"%s\" line=%d)\n",
431+
"could not parse entry (file=\"%s\" line=%lu)\n",
431432
fname, lineno, 0 );
432433
rc = LDAP_OTHER;
433434
break;
@@ -437,7 +438,7 @@ root_dse_read_file( const char *fname )
437438
if( e->e_nname.bv_len ) {
438439
Debug( LDAP_DEBUG_ANY,
439440
"root_dse_read_file: invalid rootDSE "
440-
"- dn=\"%s\" (file=\"%s\" line=%d)\n",
441+
"- dn=\"%s\" (file=\"%s\" line=%lu)\n",
441442
e->e_dn, fname, lineno );
442443
entry_free( e );
443444
rc = LDAP_OTHER;

servers/slapd/slapadd.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ static char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
4444

4545
typedef struct Erec {
4646
Entry *e;
47-
int lineno;
48-
int nextline;
47+
unsigned long lineno;
48+
unsigned long nextline;
4949
} Erec;
5050

5151
typedef struct Trec {
5252
Entry *e;
53-
int lineno;
54-
int nextline;
53+
unsigned long lineno;
54+
unsigned long nextline;
5555
int rc;
5656
int ready;
5757
} Trec;
@@ -108,7 +108,7 @@ getrec0(Erec *erec)
108108
0);
109109

110110
if( e == NULL ) {
111-
fprintf( stderr, "%s: could not parse entry (line=%d)\n",
111+
fprintf( stderr, "%s: could not parse entry (line=%lu)\n",
112112
progname, erec->lineno );
113113
return -2;
114114
}
@@ -117,7 +117,7 @@ getrec0(Erec *erec)
117117
if( BER_BVISEMPTY( &e->e_nname ) &&
118118
!BER_BVISEMPTY( be->be_nsuffix ))
119119
{
120-
fprintf( stderr, "%s: line %d: "
120+
fprintf( stderr, "%s: line %lu: "
121121
"cannot add entry with empty dn=\"%s\"",
122122
progname, erec->lineno, e->e_dn );
123123
bd = select_backend( &e->e_nname, nosubordinates );
@@ -144,7 +144,7 @@ getrec0(Erec *erec)
144144
/* check backend */
145145
bd = select_backend( &e->e_nname, nosubordinates );
146146
if ( bd != be ) {
147-
fprintf( stderr, "%s: line %d: "
147+
fprintf( stderr, "%s: line %lu: "
148148
"database #%d (%s) not configured to hold \"%s\"",
149149
progname, erec->lineno,
150150
dbnum,
@@ -432,7 +432,7 @@ slapadd( int argc, char **argv )
432432
id = be->be_entry_put( be, erec.e, &bvtext );
433433
if( id == NOID ) {
434434
fprintf( stderr, "%s: could not add entry dn=\"%s\" "
435-
"(line=%d): %s\n", progname, erec.e->e_dn,
435+
"(line=%lu): %s\n", progname, erec.e->e_dn,
436436
erec.lineno, bvtext.bv_val );
437437
rc = EXIT_FAILURE;
438438
if( continuemode ) {

servers/slapd/slapcommon.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ slap_tool_init(
456456
} break;
457457

458458
case 'j': /* jump to linenumber */
459-
if ( lutil_atoi( &jumpline, optarg ) ) {
459+
if ( lutil_atoul( &jumpline, optarg ) ) {
460460
usage( tool, progname );
461461
}
462462
break;

servers/slapd/slapcommon.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ typedef struct tool_vars {
4343
int tv_continuemode;
4444
int tv_nosubordinates;
4545
int tv_dryrun;
46-
int tv_jumpline;
47-
struct berval tv_sub_ndn;
4846
int tv_scope;
47+
unsigned long tv_jumpline;
48+
struct berval tv_sub_ndn;
4949
Filter *tv_filter;
5050
struct LDIFFP *tv_ldiffp;
5151
struct berval tv_baseDN;

0 commit comments

Comments
 (0)