copy fixes to simplify link copying and always do the right thing.
authorErik Andersen <andersen@codepoet.org>
Sat, 29 Jan 2000 05:52:40 +0000 (05:52 -0000)
committerErik Andersen <andersen@codepoet.org>
Sat, 29 Jan 2000 05:52:40 +0000 (05:52 -0000)
ping could segfault because I'm an idiot, and tried to put a value
in where I hadn't allocated storage.  choke.
 -Erik

networking/ping.c
ping.c
utility.c

index 2b6e7f5..5cadac3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ping.c,v 1.7 2000/01/26 20:06:48 erik Exp $
+ * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $
  * Mini ping implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -312,18 +312,14 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
 
 static void ping(char *host)
 {
-    struct protoent *proto;
+    struct protoent *proto=NULL;
     struct hostent *h;
     char buf[MAXHOSTNAMELEN];
     char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
     int sockopt;
     
-    if (!(proto = getprotobyname("icmp"))) {
-       /* getprotobyname failed, so just silently force 
-        * proto->p_proto to have the correct value for "icmp" */
-       proto->p_proto = 1;
-    }
-    if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { /* 1 == ICMP */
+    proto = getprotobyname("icmp");
+    if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */
        if (errno == EPERM) {
            fprintf(stderr, "ping: permission denied. (are you root?)\n");
        } else {
diff --git a/ping.c b/ping.c
index 2b6e7f5..5cadac3 100644 (file)
--- a/ping.c
+++ b/ping.c
@@ -1,5 +1,5 @@
 /*
- * $Id: ping.c,v 1.7 2000/01/26 20:06:48 erik Exp $
+ * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $
  * Mini ping implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -312,18 +312,14 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
 
 static void ping(char *host)
 {
-    struct protoent *proto;
+    struct protoent *proto=NULL;
     struct hostent *h;
     char buf[MAXHOSTNAMELEN];
     char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
     int sockopt;
     
-    if (!(proto = getprotobyname("icmp"))) {
-       /* getprotobyname failed, so just silently force 
-        * proto->p_proto to have the correct value for "icmp" */
-       proto->p_proto = 1;
-    }
-    if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { /* 1 == ICMP */
+    proto = getprotobyname("icmp");
+    if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */
        if (errno == EPERM) {
            fprintf(stderr, "ping: permission denied. (are you root?)\n");
        } else {
index c10f9bb..191701b 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -182,6 +182,11 @@ copyFile( const char *srcName, const char *destName,
            perror(destName);
            return (FALSE);
        }
+#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+       if (setModes == TRUE) {
+           lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
+       }
+#endif
     } else if (S_ISFIFO(srcStatBuf.st_mode)) {
        //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName);
        if (mkfifo(destName, 0644)) {
@@ -225,16 +230,9 @@ copyFile( const char *srcName, const char *destName,
     }
 
     if (setModes == TRUE) {
-       if (! S_ISLNK(srcStatBuf.st_mode)) {
-           chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
-           /* Never chmod a symlink; it follows the link */
-           chmod(destName, srcStatBuf.st_mode);
-       }
-#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
-       else { 
-           lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
-       }
-#endif
+       /* This is fine, since symlinks never get here */
+       chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
+       chmod(destName, srcStatBuf.st_mode);
        times.actime = srcStatBuf.st_atime;
        times.modtime = srcStatBuf.st_mtime;
        utime(destName, &times);