<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[142289] trunk/base/src/pextlib1.0/sip_copy_proc.c</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/142289">142289</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2015-11-09 10:25:12 -0800 (Mon, 09 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>base: pextlib/sip_copy_proc: unify whitespace</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcpextlib10sip_copy_procc">trunk/base/src/pextlib1.0/sip_copy_proc.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcpextlib10sip_copy_procc"></a>
<div class="modfile"><h4>Modified: trunk/base/src/pextlib1.0/sip_copy_proc.c (142288 => 142289)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/sip_copy_proc.c        2015-11-09 11:01:06 UTC (rev 142288)
+++ trunk/base/src/pextlib1.0/sip_copy_proc.c        2015-11-09 18:25:12 UTC (rev 142289)
</span><span class="lines">@@ -59,14 +59,14 @@
</span><span class="cx"> * Frees an array of strings and the array itself.
</span><span class="cx"> */
</span><span class="cx"> static void free_argv(char *argv[]) {
</span><del>-        char **arg = argv;
-        while (arg && *arg) {
-                free(*arg);
-                *arg = NULL;
-                arg++;
-        }
</del><ins>+ char **arg = argv;
+ while (arg && *arg) {
+ free(*arg);
+ *arg = NULL;
+ arg++;
+ }
</ins><span class="cx">
</span><del>-        free(argv);
</del><ins>+ free(argv);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> typedef enum _copy_needed_return_t {
</span><span class="lines">@@ -119,149 +119,149 @@
</span><span class="cx"> static copy_needed_return_t copy_needed(const char *path, char *const argv[],
</span><span class="cx"> char **outargv[], char *const environ[], struct stat *st) {
</span><span class="cx"> #ifndef SF_RESTRICTED /* no system integrity protection */
</span><del>-        return copy_not_needed;
</del><ins>+ return copy_not_needed;
</ins><span class="cx"> #else /* defined(SF_RESTRICTED) */
</span><del>-        // check whether DYLD_INSERT_LIBRARIES is set
-        bool dyld_insert_libraries_present = false;
-        char *const *env = environ;
-        while (env && *env) {
-                if (strncmp("DYLD_INSERT_LIBRARIES=", *env, strlen("DYLD_INSERT_LIBRARIES=")) == 0) {
-                        dyld_insert_libraries_present = true;
-                        break;
-                }
-                env++;
-        }
-        // if we didn't find DYLD_INSERT_LIBRARIES, a copy isn't needed
-        if (!dyld_insert_libraries_present) {
-                return copy_not_needed;
-        }
</del><ins>+ // check whether DYLD_INSERT_LIBRARIES is set
+ bool dyld_insert_libraries_present = false;
+ char *const *env = environ;
+ while (env && *env) {
+ if (strncmp("DYLD_INSERT_LIBRARIES=", *env, strlen("DYLD_INSERT_LIBRARIES=")) == 0) {
+ dyld_insert_libraries_present = true;
+ break;
+ }
+ env++;
+ }
+ // if we didn't find DYLD_INSERT_LIBRARIES, a copy isn't needed
+ if (!dyld_insert_libraries_present) {
+ return copy_not_needed;
+ }
</ins><span class="cx">
</span><del>-        // open file to check for shebangs
-        const char *realpath = path;
-        size_t new_argc = 0;
-        char **new_argv = NULL;
-        FILE *f = fopen(path, "r");
-        if (!f) {
-                // if opening fails we won't be able to copy anyway
-                return copy_not_needed;
-        }
</del><ins>+ // open file to check for shebangs
+ const char *realpath = path;
+ size_t new_argc = 0;
+ char **new_argv = NULL;
+ FILE *f = fopen(path, "r");
+ if (!f) {
+ // if opening fails we won't be able to copy anyway
+ return copy_not_needed;
+ }
</ins><span class="cx">
</span><del>-        /* no error checking for fgetc(3) here, because this isn't a shebang if an
-         * error occurs */
-        if (fgetc(f) == '#' && fgetc(f) == '!') {
-                /* This is an interpreted script. The interpreter's flags are what
-                 * affects whether DYLD_* is stripped, so read the interpreter's path
-                 * from the file to check that instead. Additionally, read any flags
-                 * that may be passed to the interpreter, since we'll have to do the
-                 * shebang expansion in user space if we move the interpreter. */
-                char *linep = NULL;
-                size_t linecapp = 0;
-                // read first line to get the interpreter and its arguments
-                if (getline(&linep, &linecapp, f) > 0) {
-                        char *ctxt;
</del><ins>+ /* no error checking for fgetc(3) here, because this isn't a shebang if an
+ * error occurs */
+ if (fgetc(f) == '#' && fgetc(f) == '!') {
+ /* This is an interpreted script. The interpreter's flags are what
+ * affects whether DYLD_* is stripped, so read the interpreter's path
+ * from the file to check that instead. Additionally, read any flags
+ * that may be passed to the interpreter, since we'll have to do the
+ * shebang expansion in user space if we move the interpreter. */
+ char *linep = NULL;
+ size_t linecapp = 0;
+ // read first line to get the interpreter and its arguments
+ if (getline(&linep, &linecapp, f) > 0) {
+ char *ctxt;
</ins><span class="cx"> char *word;
</span><span class="cx"> size_t idx;
</span><del>-                        // do word splitting on the interpreter line and store it in new_argv
-                        for (idx = 0, word = strtok_r(linep, " \t\n", &ctxt);
-                                        word != NULL;
-                                        idx++, word = strtok_r(NULL, " \t\n", &ctxt)) {
-                                // make sure we have enough space allocated
-                                if (new_argv == NULL) {
-                                        if ((new_argv = malloc(2 * sizeof(*new_argv))) == NULL) {
</del><ins>+ // do word splitting on the interpreter line and store it in new_argv
+ for (idx = 0, word = strtok_r(linep, " \t\n", &ctxt);
+ word != NULL;
+ idx++, word = strtok_r(NULL, " \t\n", &ctxt)) {
+ // make sure we have enough space allocated
+ if (new_argv == NULL) {
+ if ((new_argv = malloc(2 * sizeof(*new_argv))) == NULL) {
</ins><span class="cx"> free(linep);
</span><span class="cx"> return copy_needed_error;
</span><del>-                                        }
-                                        new_argc = 1;
</del><ins>+ }
+ new_argc = 1;
</ins><span class="cx">
</span><del>-                                        // new_argv[0] will be overwritten in a second
-                                        // new_argv[1] is the terminating NULL
-                                        new_argv[0] = NULL;
-                                        new_argv[1] = NULL;
-                                } else if (idx >= new_argc) {
-                                        // realloc to increase the size
-                                        char **oldargv = new_argv;
-                                        if ((new_argv = realloc(oldargv, (idx + 2) * sizeof(*new_argv))) == NULL) {
-                                                free_argv(oldargv);
</del><ins>+ // new_argv[0] will be overwritten in a second
+ // new_argv[1] is the terminating NULL
+ new_argv[0] = NULL;
+ new_argv[1] = NULL;
+ } else if (idx >= new_argc) {
+ // realloc to increase the size
+ char **oldargv = new_argv;
+ if ((new_argv = realloc(oldargv, (idx + 2) * sizeof(*new_argv))) == NULL) {
+ free_argv(oldargv);
</ins><span class="cx"> free(linep);
</span><span class="cx"> return copy_needed_error;
</span><del>-                                        }
-                                        new_argc = idx + 1;
-                                }
</del><ins>+ }
+ new_argc = idx + 1;
+ }
</ins><span class="cx">
</span><del>-                                // store a copy of the word in new_argv
-                                new_argv[idx] = strdup(word);
-                                if (!new_argv[idx]) {
-                                        free_argv(new_argv);
</del><ins>+ // store a copy of the word in new_argv
+ new_argv[idx] = strdup(word);
+ if (!new_argv[idx]) {
+ free_argv(new_argv);
</ins><span class="cx"> free(linep);
</span><span class="cx"> return copy_needed_error;
</span><del>-                                }
</del><ins>+ }
</ins><span class="cx"> new_argv[idx + 1] = NULL;
</span><del>-                        }
</del><ins>+ }
</ins><span class="cx">
</span><del>-                        free(linep);
</del><ins>+ free(linep);
</ins><span class="cx">
</span><del>-                        if (new_argv && *new_argv) {
-                                // interpreter found, check that instead of given path
-                                realpath = *new_argv;
-                        }
-                }
-        }
</del><ins>+ if (new_argv && *new_argv) {
+ // interpreter found, check that instead of given path
+ realpath = *new_argv;
+ }
+ }
+ }
</ins><span class="cx">
</span><del>-        // check whether the binary has SF_RESTRICTED and isn't SUID/SGID
-        if (-1 == stat(realpath, st)) {
-                // on error, return and let execve(2) deal with it
-                free_argv(new_argv);
-                return copy_not_needed;
-        } else {
-                if (!(st->st_flags & SF_RESTRICTED)) {
-                        // no SIP on this binary
-                        free_argv(new_argv);
-                        return copy_not_needed;
-                }
-                if ((st->st_flags & (S_ISUID | S_ISGID)) > 0) {
-                        // the binary is SUID/SGID, which would get lost when copying;
-                        // DYLD_ variables are stripped for SUID/SGID binaries anyway
-                        free_argv(new_argv);
-                        return copy_not_needed;
-                }
-        }
</del><ins>+ // check whether the binary has SF_RESTRICTED and isn't SUID/SGID
+ if (-1 == stat(realpath, st)) {
+ // on error, return and let execve(2) deal with it
+ free_argv(new_argv);
+ return copy_not_needed;
+ } else {
+ if (!(st->st_flags & SF_RESTRICTED)) {
+ // no SIP on this binary
+ free_argv(new_argv);
+ return copy_not_needed;
+ }
+ if ((st->st_flags & (S_ISUID | S_ISGID)) > 0) {
+ // the binary is SUID/SGID, which would get lost when copying;
+ // DYLD_ variables are stripped for SUID/SGID binaries anyway
+ free_argv(new_argv);
+ return copy_not_needed;
+ }
+ }
</ins><span class="cx">
</span><del>-        // prefix the shebang line to the original argv
-        if (new_argv != NULL) {
</del><ins>+ // prefix the shebang line to the original argv
+ if (new_argv != NULL) {
</ins><span class="cx"> size_t argc = 0;
</span><span class="cx"> for (char *const *argvwalk = argv; argvwalk && *argvwalk; ++argvwalk) {
</span><span class="cx"> argc++;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-                // realloc to increase the size
-                char **oldargv = new_argv;
-                if ((new_argv = realloc(oldargv, (new_argc + argc + 1) * sizeof(*new_argv))) == NULL) {
-                        free_argv(oldargv);
</del><ins>+ // realloc to increase the size
+ char **oldargv = new_argv;
+ if ((new_argv = realloc(oldargv, (new_argc + argc + 1) * sizeof(*new_argv))) == NULL) {
+ free_argv(oldargv);
</ins><span class="cx"> return copy_needed_error;
</span><del>-                }
</del><ins>+ }
</ins><span class="cx">
</span><del>-                new_argv[new_argc] = strdup(path);
-                if (!new_argv[new_argc]) {
</del><ins>+ new_argv[new_argc] = strdup(path);
+ if (!new_argv[new_argc]) {
</ins><span class="cx"> free_argv(new_argv);
</span><span class="cx"> return copy_needed_error;
</span><del>-                }
</del><ins>+ }
</ins><span class="cx"> new_argv[new_argc + 1] = NULL;
</span><span class="cx">
</span><del>-                for (size_t idx = 1; idx < argc; ++idx) {
-                        new_argv[new_argc + idx] = strdup(argv[idx]);
-                        if (!new_argv[new_argc + idx]) {
</del><ins>+ for (size_t idx = 1; idx < argc; ++idx) {
+ new_argv[new_argc + idx] = strdup(argv[idx]);
+ if (!new_argv[new_argc + idx]) {
</ins><span class="cx"> free_argv(new_argv);
</span><span class="cx"> return copy_needed_error;
</span><del>-                        }
</del><ins>+ }
</ins><span class="cx"> new_argv[new_argc + idx + 1] = NULL;
</span><del>-                }
</del><ins>+ }
</ins><span class="cx">
</span><del>-                new_argc = new_argc + argc;
</del><ins>+ new_argc = new_argc + argc;
</ins><span class="cx">
</span><del>-                *outargv = new_argv;
-        }
</del><ins>+ *outargv = new_argv;
+ }
</ins><span class="cx">
</span><del>-        return copy_is_needed;
</del><ins>+ return copy_is_needed;
</ins><span class="cx"> #endif /* defined(SF_RESTRICTED) */
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>