Permalink
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...
ChrisJohnsen committed Aug 2, 2012
1 parent 7420a3f commit ec6cdf5b2a135d5740bffff424c693f513280ef5
Showing with 7 additions and 0 deletions.
  1. +7 −0 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,13 +186,18 @@ 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++)
newargs[arg-1] = argv[arg];
newargs[arg-1] = NULL;
}
+exec_it:
if (execvp(file, newargs ? newargs : argv+1) < 0)
die_errno(3, "execv failed");

0 comments on commit ec6cdf5

Please sign in to comment.