]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/options.c
create log file safely, don't create world-writable files
[ppp.git] / pppd / options.c
index edee078245a2d43b1699befbb2b25468c698bf4a..66770a5918606578c9e7b6e10cb4d19b7dc9d13d 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: options.c,v 1.66 1999/09/11 12:08:58 paulus Exp $"
+#define RCSID  "$Id: options.c,v 1.68 1999/11/15 03:55:37 paulus Exp $"
 
 #include <ctype.h>
 #include <stdio.h>
@@ -1413,7 +1413,7 @@ setipaddr(arg)
      */
     if (colon != arg) {
        *colon = '\0';
-       if ((local = inet_addr(arg)) == -1) {
+       if ((local = inet_addr(arg)) == (u_int32_t) -1) {
            if ((hp = gethostbyname(arg)) == NULL) {
                option_error("unknown host: %s", arg);
                return -1;
@@ -1434,7 +1434,7 @@ setipaddr(arg)
      * If colon last character, then no remote addr.
      */
     if (*++colon != '\0') {
-       if ((remote = inet_addr(colon)) == -1) {
+       if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
            if ((hp = gethostbyname(colon)) == NULL) {
                option_error("unknown host: %s", colon);
                return -1;
@@ -1478,7 +1478,7 @@ setnetmask(argv)
        b = strtoul(p, &endp, 0);
        if (endp == p)
            break;
-       if (b < 0 || b > 255) {
+       if (b > 255) {
            if (n == 3) {
                /* accept e.g. 0xffffff00 */
                p = endp;
@@ -1523,7 +1523,9 @@ setlogfile(argv)
 
     if (!privileged_option)
        seteuid(getuid());
-    fd = open(*argv, O_WRONLY | O_APPEND);
+    fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
+    if (fd < 0 && errno == EEXIST)
+       fd = open(*argv, O_WRONLY | O_APPEND);
     err = errno;
     if (!privileged_option)
        seteuid(0);