@@ -349,6 +349,7 @@ int main(int argc, char **argv) {
349349 size_t ipset_reduce_factor = 120 ;
350350 size_t ipset_reduce_min_accepted = 16384 ;
351351 int ret = 0 , quiet = 0 ;
352+ int inputs = 0 ;
352353
353354 ipset * root = NULL , * ips = NULL , * first = NULL , * second = NULL ;
354355 int i , mode = MODE_COMBINE , header = 0 , read_second = 0 ;
@@ -565,9 +566,8 @@ int main(int argc, char **argv) {
565566 }
566567 else {
567568 if (!strcmp (argv [i ], "-" )) {
568- ips = ipset_load (NULL );
569-
570- if (!ips ) {
569+ inputs ++ ;
570+ if (!(ips = ipset_load (NULL ))) {
571571 fprintf (stderr , "%s: Cannot load ipset from stdin\n" , PROG );
572572 exit (1 );
573573 }
@@ -585,6 +585,8 @@ int main(int argc, char **argv) {
585585 }
586586 }
587587 else if (argv [i ][0 ] == '@' ) {
588+ inputs ++ ;
589+
588590 /* Handle @filename as a file list or directory */
589591 const char * listname = argv [i ] + 1 ; /* Skip the @ character */
590592 struct stat st ;
@@ -629,11 +631,10 @@ int main(int argc, char **argv) {
629631 fprintf (stderr , "%s: Loading file %s from directory %s\n" , PROG , entry -> d_name , listname );
630632
631633 /* Load the file as an independent ipset */
632- ips = ipset_load (filepath );
633- if (!ips ) {
634+ if (!(ips = ipset_load (filepath ))) {
634635 fprintf (stderr , "%s: Cannot load file %s from directory %s\n" ,
635636 PROG , filepath , listname );
636- continue ;
637+ exit ( 1 ) ;
637638 }
638639
639640 files_loaded = 1 ;
@@ -700,11 +701,10 @@ int main(int argc, char **argv) {
700701 fprintf (stderr , "%s: Loading file %s from list (line %d)\n" , PROG , s , lineid );
701702
702703 /* Load the file as an independent ipset */
703- ips = ipset_load (s );
704- if (!ips ) {
704+ if (!(ips = ipset_load (s ))) {
705705 fprintf (stderr , "%s: Cannot load file %s from list %s (line %d)\n" ,
706706 PROG , s , listname , lineid );
707- continue ;
707+ exit ( 1 ) ;
708708 }
709709
710710 files_loaded = 1 ;
@@ -736,11 +736,10 @@ int main(int argc, char **argv) {
736736 }
737737 }
738738 else {
739- ips = ipset_load (argv [i ]);
740-
741- if (!ips ) {
739+ inputs ++ ;
740+ if (!(ips = ipset_load (argv [i ]))) {
742741 fprintf (stderr , "%s: Cannot load ipset: %s\n" , PROG , argv [i ]);
743- continue ; /* Continue with other arguments instead of exiting */
742+ exit ( 1 );
744743 }
745744
746745 if (read_second ) {
@@ -760,21 +759,21 @@ int main(int argc, char **argv) {
760759
761760 /*
762761 * if no ipset was given on the command line
763- * assume stdin, but only if no other filenames were specified
762+ * assume stdin, regardless of whether other options were specified
764763 */
765764
766- if (!root && argc <= 1 ) {
765+ if (!inputs ) {
767766 if (unlikely (debug ))
768- fprintf (stderr , "%s: No inputs provided, reading from stdin\n" , PROG );
769-
770- first = root = ipset_load (NULL );
771- if (!root ) {
772- fprintf (stderr , "%s: No ipsets to merge.\n" , PROG );
767+ fprintf (stderr , "%s: No input files provided, reading from stdin\n" , PROG );
768+
769+ if (!(first = root = ipset_load (NULL ))) {
770+ fprintf (stderr , "%s: Cannot load ipset from stdin\n" , PROG );
773771 exit (1 );
774772 }
775773 }
776- else if (!root ) {
777- /* We had parameters but still ended up with no valid ipsets */
774+
775+ if (!root ) {
776+ // impossible situation since we fail if no ipset is loaded
778777 fprintf (stderr , "%s: No valid ipsets to merge from the provided inputs.\n" , PROG );
779778 exit (1 );
780779 }
0 commit comments