Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

wrapper: handle malloc() errors for -l processing

Handle malloc() errors that might come up while doing "login"
processing (massaging the new command's argv[0] when the "-l" option
is used).

Skip the string/argument manipulation and just use the strings that
were given in the wrapper's argv. The new program will not find that
its argv[0] starts with a dash, but we will at least give it
a chance to try to run (although it may also face serious problems).
  • Loading branch information...
commit ec6cdf5b2a135d5740bffff424c693f513280ef5 1 parent 7420a3f
@ChrisJohnsen authored
Showing with 7 additions and 0 deletions.
  1. +7 −0 reattach-to-user-namespace.c
View
7 reattach-to-user-namespace.c
@@ -175,6 +175,8 @@ int main(int argc, char *argv[]) {
* it with '-'.
*/
char *arg0 = malloc(strlen(file) + 2);
+ if (!arg0)
+ goto exec_it;
*arg0 = '-';
char *slash = strrchr(file, '/');
if (slash && slash[1])
@@ -184,6 +186,10 @@ int main(int argc, char *argv[]) {
/* use the rest of the args as they are */
newargs = malloc(sizeof(*newargs) * (argc));
+ if (!newargs) {
+ free(arg0);
+ goto exec_it;
+ }
newargs[0] = arg0;
int arg = 2;
for(; arg < argc; arg++)
@@ -191,6 +197,7 @@ int main(int argc, char *argv[]) {
newargs[arg-1] = NULL;
}
+exec_it:
if (execvp(file, newargs ? newargs : argv+1) < 0)
die_errno(3, "execv failed");
Please sign in to comment.
Something went wrong with that request. Please try again.