@@ -204,7 +204,7 @@ function test_cyclic_link_protection(callback) {
204
204
fs . symlinkSync ( t [ 1 ] , t [ 0 ] , 'dir' ) ;
205
205
unlink . push ( t [ 0 ] ) ;
206
206
} ) ;
207
- assert . throws ( function ( ) { fs . realpathSync ( entry ) ; } ) ;
207
+ assert . throws ( function ( ) { fs . realpathSync ( entry ) ; } , / E L O O P / ) ;
208
208
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
209
209
assert . ok ( err && true ) ;
210
210
return true ;
@@ -461,6 +461,76 @@ function test_abs_with_kids(cb) {
461
461
} ) ;
462
462
}
463
463
464
+ function test_deep_symlink_eloop ( callback ) {
465
+ console . log ( 'test_deep_symlink_eloop' ) ;
466
+ if ( skipSymlinks ) {
467
+ common . skip ( 'symlink test (no privs)' ) ;
468
+ return runNextTest ( ) ;
469
+ }
470
+
471
+ const deepsymPath = path . join ( targetsAbsDir , 'deep-symlink' ) ;
472
+ const aPath = path . join ( deepsymPath , 'a' ) ;
473
+ const bSympath = path . join ( aPath , 'b' ) ;
474
+ const cleanupPaths = [ bSympath ] ;
475
+ const pRepeat = 33 ;
476
+
477
+ function cleanup ( ) {
478
+ while ( cleanupPaths . length > 0 ) {
479
+ try { fs . unlinkSync ( cleanupPaths . pop ( ) ) ; } catch ( e ) { }
480
+ }
481
+ }
482
+
483
+ fs . mkdirSync ( deepsymPath ) ;
484
+ fs . mkdirSync ( aPath ) ;
485
+ fs . mkdirSync ( path . join ( targetsAbsDir , 'deep-symlink' , 'c' ) ) ;
486
+ try { fs . unlinkSync ( bSympath ) ; } catch ( e ) { }
487
+ fs . symlinkSync ( deepsymPath , bSympath ) ;
488
+
489
+ // First test sync calls.
490
+
491
+ const testPath = aPath + '/b/a' . repeat ( pRepeat ) + '/b/c' ;
492
+ const resolvedPath = fs . realpathSync ( testPath ) ;
493
+ assert . equal ( path . relative ( deepsymPath , resolvedPath ) , 'c' ) ;
494
+
495
+ var reallyBigSymPath = deepsymPath ;
496
+ var prev = null ;
497
+
498
+ // Make massively deep set of symlinks
499
+ for ( var i = 97 ; i < 105 ; i ++ ) {
500
+ for ( var j = 97 ; j < 101 ; j ++ ) {
501
+ const link = String . fromCharCode ( i ) + String . fromCharCode ( j ) ;
502
+ const link_path = path . join ( deepsymPath , link ) ;
503
+ cleanupPaths . push ( link_path ) ;
504
+ try { fs . unlinkSync ( link_path ) ; } catch ( e ) { }
505
+ if ( prev )
506
+ fs . symlinkSync ( link_path , prev ) ;
507
+ reallyBigSymPath += '/' + link ;
508
+ prev = link_path ;
509
+ }
510
+ }
511
+ fs . symlinkSync ( deepsymPath , prev ) ;
512
+ reallyBigSymPath += '/' + path . basename ( prev ) ;
513
+
514
+ assert . throws ( ( ) => fs . realpathSync ( reallyBigSymPath ) , / E L O O P / ) ;
515
+
516
+ // Now test async calls.
517
+
518
+ fs . realpath ( testPath , ( err , resolvedPath ) => {
519
+ if ( err ) throw err ;
520
+ assert . equal ( path . relative ( deepsymPath , resolvedPath ) , 'c' ) ;
521
+ checkAsyncReallyBigSymPath ( ) ;
522
+ } ) ;
523
+
524
+ function checkAsyncReallyBigSymPath ( ) {
525
+ fs . realpath ( reallyBigSymPath , ( err , path ) => {
526
+ assert . ok ( err ) ;
527
+ assert . ok ( / E L O O P / . test ( err . message ) ) ;
528
+ cleanup ( ) ;
529
+ runNextTest ( ) ;
530
+ } ) ;
531
+ }
532
+ }
533
+
464
534
// ----------------------------------------------------------------------------
465
535
466
536
var tests = [
@@ -476,7 +546,8 @@ var tests = [
476
546
test_non_symlinks ,
477
547
test_escape_cwd ,
478
548
test_abs_with_kids ,
479
- test_up_multiple
549
+ test_up_multiple ,
550
+ test_deep_symlink_eloop ,
480
551
] ;
481
552
var numtests = tests . length ;
482
553
var testsRun = 0 ;
0 commit comments