1
- /* $OpenBSD: netcat.c,v 1.203 2019/02/26 17:32:47 jsing Exp $ */
1
+ /* $OpenBSD: netcat.c,v 1.206 2019/08/08 16:49:35 mestre Exp $ */
2
2
/*
3
3
* Copyright (c) 2001 Eric Jackson <[email protected] >
4
4
* Copyright (c) 2015 Bob Beck. All rights reserved.
@@ -393,6 +393,7 @@ main(int argc, char *argv[])
393
393
err (1 , "unveil" );
394
394
}
395
395
} else {
396
+ /* no filesystem visibility */
396
397
if (unveil ("/" , "" ) == -1 )
397
398
err (1 , "unveil" );
398
399
}
@@ -578,7 +579,7 @@ main(int argc, char *argv[])
578
579
close (s );
579
580
s = local_listen (host , uport , hints );
580
581
}
581
- if (s < 0 )
582
+ if (s == -1 )
582
583
err (1 , NULL );
583
584
if (uflag && kflag ) {
584
585
/*
@@ -600,11 +601,11 @@ main(int argc, char *argv[])
600
601
len = sizeof (z );
601
602
rv = recvfrom (s , buf , sizeof (buf ), MSG_PEEK ,
602
603
(struct sockaddr * )& z , & len );
603
- if (rv < 0 )
604
+ if (rv == -1 )
604
605
err (1 , "recvfrom" );
605
606
606
607
rv = connect (s , (struct sockaddr * )& z , len );
607
- if (rv < 0 )
608
+ if (rv == -1 )
608
609
err (1 , "connect" );
609
610
610
611
if (vflag )
@@ -638,7 +639,7 @@ main(int argc, char *argv[])
638
639
tls_free (tls_cctx );
639
640
}
640
641
if (family == AF_UNIX && uflag ) {
641
- if (connect (s , NULL , 0 ) < 0 )
642
+ if (connect (s , NULL , 0 ) == -1 )
642
643
err (1 , "connect" );
643
644
}
644
645
@@ -749,7 +750,7 @@ unix_bind(char *path, int flags)
749
750
750
751
/* Create unix domain socket. */
751
752
if ((s = socket (AF_UNIX , flags | (uflag ? SOCK_DGRAM : SOCK_STREAM ),
752
- 0 )) < 0 )
753
+ 0 )) == -1 )
753
754
return -1 ;
754
755
755
756
memset (& s_un , 0 , sizeof (struct sockaddr_un ));
@@ -762,7 +763,7 @@ unix_bind(char *path, int flags)
762
763
return -1 ;
763
764
}
764
765
765
- if (bind (s , (struct sockaddr * )& s_un , sizeof (s_un )) < 0 ) {
766
+ if (bind (s , (struct sockaddr * )& s_un , sizeof (s_un )) == -1 ) {
766
767
save_errno = errno ;
767
768
close (s );
768
769
errno = save_errno ;
@@ -872,10 +873,10 @@ unix_connect(char *path)
872
873
int s , save_errno ;
873
874
874
875
if (uflag ) {
875
- if ((s = unix_bind (unix_dg_tmp_socket , SOCK_CLOEXEC )) < 0 )
876
+ if ((s = unix_bind (unix_dg_tmp_socket , SOCK_CLOEXEC )) == -1 )
876
877
return -1 ;
877
878
} else {
878
- if ((s = socket (AF_UNIX , SOCK_STREAM | SOCK_CLOEXEC , 0 )) < 0 )
879
+ if ((s = socket (AF_UNIX , SOCK_STREAM | SOCK_CLOEXEC , 0 )) == -1 )
879
880
return -1 ;
880
881
}
881
882
@@ -888,7 +889,7 @@ unix_connect(char *path)
888
889
errno = ENAMETOOLONG ;
889
890
return -1 ;
890
891
}
891
- if (connect (s , (struct sockaddr * )& s_un , sizeof (s_un )) < 0 ) {
892
+ if (connect (s , (struct sockaddr * )& s_un , sizeof (s_un )) == -1 ) {
892
893
save_errno = errno ;
893
894
close (s );
894
895
errno = save_errno ;
@@ -907,9 +908,9 @@ unix_listen(char *path)
907
908
{
908
909
int s ;
909
910
910
- if ((s = unix_bind (path , 0 )) < 0 )
911
+ if ((s = unix_bind (path , 0 )) == -1 )
911
912
return -1 ;
912
- if (listen (s , 5 ) < 0 ) {
913
+ if (listen (s , 5 ) == -1 ) {
913
914
close (s );
914
915
return -1 ;
915
916
}
@@ -939,7 +940,7 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
939
940
940
941
for (res = res0 ; res ; res = res -> ai_next ) {
941
942
if ((s = socket (res -> ai_family , res -> ai_socktype |
942
- SOCK_NONBLOCK , res -> ai_protocol )) < 0 )
943
+ SOCK_NONBLOCK , res -> ai_protocol )) == -1 )
943
944
continue ;
944
945
945
946
/* Bind to a local port or source address if specified. */
@@ -959,7 +960,7 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
959
960
errx (1 , "getaddrinfo: %s" , gai_strerror (error ));
960
961
961
962
if (bind (s , (struct sockaddr * )ares -> ai_addr ,
962
- ares -> ai_addrlen ) < 0 )
963
+ ares -> ai_addrlen ) == -1 )
963
964
err (1 , "bind failed" );
964
965
freeaddrinfo (ares );
965
966
}
@@ -1041,7 +1042,7 @@ local_listen(const char *host, const char *port, struct addrinfo hints)
1041
1042
1042
1043
for (res = res0 ; res ; res = res -> ai_next ) {
1043
1044
if ((s = socket (res -> ai_family , res -> ai_socktype ,
1044
- res -> ai_protocol )) < 0 )
1045
+ res -> ai_protocol )) == -1 )
1045
1046
continue ;
1046
1047
1047
1048
#ifdef SO_REUSEPORT
@@ -1063,7 +1064,7 @@ local_listen(const char *host, const char *port, struct addrinfo hints)
1063
1064
}
1064
1065
1065
1066
if (!uflag && s != -1 ) {
1066
- if (listen (s , 1 ) < 0 )
1067
+ if (listen (s , 1 ) == -1 )
1067
1068
err (1 , "listen" );
1068
1069
}
1069
1070
if (vflag && s != -1 ) {
@@ -1473,12 +1474,12 @@ build_ports(char *p)
1473
1474
for (x = 0 ; x <= hi - lo ; x ++ ) {
1474
1475
cp = arc4random_uniform (x + 1 );
1475
1476
portlist [x ] = portlist [cp ];
1476
- if (asprintf (& portlist [cp ], "%d" , x + lo ) < 0 )
1477
+ if (asprintf (& portlist [cp ], "%d" , x + lo ) == -1 )
1477
1478
err (1 , "asprintf" );
1478
1479
}
1479
1480
} else { /* Load ports sequentially. */
1480
1481
for (cp = lo ; cp <= hi ; cp ++ ) {
1481
- if (asprintf (& portlist [x ], "%d" , cp ) < 0 )
1482
+ if (asprintf (& portlist [x ], "%d" , cp ) == -1 )
1482
1483
err (1 , "asprintf" );
1483
1484
x ++ ;
1484
1485
}
0 commit comments