Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumphijack Return value audit: properly set errno and...



details:   https://anonhg.NetBSD.org/src/rev/490b413ed343
branches:  trunk
changeset: 762585:490b413ed343
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Feb 23 15:44:38 2011 +0000

description:
Return value audit: properly set errno and return -1.
Fixes at least cross-kernel mv(1).

diffstat:

 lib/librumphijack/hijack.c |  40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diffs (101 lines):

diff -r 2e104d7fc9b1 -r 490b413ed343 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c        Wed Feb 23 15:29:21 2011 +0000
+++ b/lib/librumphijack/hijack.c        Wed Feb 23 15:44:38 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $       */
+/*      $NetBSD: hijack.c,v 1.66 2011/02/23 15:44:38 pooka Exp $       */
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.65 2011/02/23 15:29:21 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.66 2011/02/23 15:44:38 pooka Exp $");
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -722,7 +722,8 @@
                else
                        prefixgap = rumpprefixlen; /* ``/pfx+/path'' */
                if (len <= prefixgap) {
-                       return ERANGE;
+                       errno = ERANGE;
+                       return -1;
                }
 
                op___getcwd = GETSYSCALL(rump, __GETCWD);
@@ -754,15 +755,19 @@
        int (*op_rename)(const char *, const char *);
 
        if (path_isrump(from)) {
-               if (!path_isrump(to))
-                       return EXDEV;
+               if (!path_isrump(to)) {
+                       errno = EXDEV;
+                       return -1;
+               }
 
                from = path_host2rump(from);
                to = path_host2rump(to);
                op_rename = GETSYSCALL(rump, RENAME);
        } else {
-               if (path_isrump(to))
-                       return EXDEV;
+               if (path_isrump(to)) {
+                       errno = EXDEV;
+                       return -1;
+               }
 
                op_rename = GETSYSCALL(host, RENAME);
        }
@@ -1008,8 +1013,10 @@
        DPRINTF(("dup2 -> %d (o) -> %d (n)\n", oldd, newd));
 
        if (fd_isrump(oldd)) {
-               if (!(newd >= 0 && newd <= 2))
-                       return EBADF;
+               if (!(newd >= 0 && newd <= 2)) {
+                       errno = EBADF;
+                       return -1;
+               }
                oldd = fd_host2rump(oldd);
                if (oldd == newd) {
                        SETDUP2(newd);
@@ -1082,8 +1089,10 @@
        if (dup2mask) {
                snprintf(buf, sizeof(buf), "RUMPHIJACK__DUP2MASK=%u", dup2mask);
                dup2str = malloc(strlen(buf)+1);
-               if (dup2str == NULL)
-                       return ENOMEM;
+               if (dup2str == NULL) {
+                       errno = ENOMEM;
+                       return -1;
+               }
                strcpy(dup2str, buf);
                bonus++;
        } else {
@@ -1102,7 +1111,8 @@
        newenv = malloc(sizeof(*newenv) * nelem+bonus);
        if (newenv == NULL) {
                free(dup2str);
-               return ENOMEM;
+               errno = ENOMEM;
+               return -1;
        }
        memcpy(newenv, envp, nelem*sizeof(*newenv));
        if (dup2str) {
@@ -1502,8 +1512,10 @@
                ev = &changelist[i];
                if (ev->filter == EVFILT_READ || ev->filter == EVFILT_WRITE ||
                    ev->filter == EVFILT_VNODE) {
-                       if (fd_isrump((int)ev->ident))
-                               return ENOTSUP;
+                       if (fd_isrump((int)ev->ident)) {
+                               errno = ENOTSUP;
+                               return -1;
+                       }
                }
        }
 



Home | Main Index | Thread Index | Old Index