diff options
author | Matt Kraai <kraai@debian.org> | 2000-09-13 02:08:21 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-09-13 02:08:21 +0000 |
commit | b89075298edf0a471b9046b1f3c8a936e18ead20 (patch) | |
tree | db429d39a26d21da0e47041985ead39ea16a795b /sh.c | |
parent | 23ad7f7f06c94d74d53fc01f96df19d071f4c9ce (diff) | |
download | busybox-w32-b89075298edf0a471b9046b1f3c8a936e18ead20.tar.gz busybox-w32-b89075298edf0a471b9046b1f3c8a936e18ead20.tar.bz2 busybox-w32-b89075298edf0a471b9046b1f3c8a936e18ead20.zip |
Fix unchecked calls to {m,c,re}alloc so that they print an error and
exit rather than segfaulting (what an improvement).
Diffstat (limited to 'sh.c')
-rw-r--r-- | sh.c | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -787,8 +787,7 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr, | |||
787 | *dst = '\0'; | 787 | *dst = '\0'; |
788 | } else if (!rc) { | 788 | } else if (!rc) { |
789 | argcAlloced += (prog->globResult.gl_pathc - i); | 789 | argcAlloced += (prog->globResult.gl_pathc - i); |
790 | prog->argv = | 790 | prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv)); |
791 | realloc(prog->argv, argcAlloced * sizeof(*prog->argv)); | ||
792 | memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i, | 791 | memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i, |
793 | sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i)); | 792 | sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i)); |
794 | argc_l += (prog->globResult.gl_pathc - i - 1); | 793 | argc_l += (prog->globResult.gl_pathc - i - 1); |
@@ -837,7 +836,7 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi | |||
837 | Getting clean memory relieves us of the task of NULL | 836 | Getting clean memory relieves us of the task of NULL |
838 | terminating things and makes the rest of this look a bit | 837 | terminating things and makes the rest of this look a bit |
839 | cleaner (though it is, admittedly, a tad less efficient) */ | 838 | cleaner (though it is, admittedly, a tad less efficient) */ |
840 | job->cmdBuf = command = calloc(2*strlen(*commandPtr) + 1, sizeof(char)); | 839 | job->cmdBuf = command = xcalloc(2*strlen(*commandPtr) + 1, sizeof(char)); |
841 | job->text = NULL; | 840 | job->text = NULL; |
842 | 841 | ||
843 | prog = job->progs; | 842 | prog = job->progs; |
@@ -876,9 +875,9 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi | |||
876 | /* +1 here leaves room for the NULL which ends argv */ | 875 | /* +1 here leaves room for the NULL which ends argv */ |
877 | if ((argc_l + 1) == argvAlloced) { | 876 | if ((argc_l + 1) == argvAlloced) { |
878 | argvAlloced += 5; | 877 | argvAlloced += 5; |
879 | prog->argv = realloc(prog->argv, | 878 | prog->argv = xrealloc(prog->argv, |
880 | sizeof(*prog->argv) * | 879 | sizeof(*prog->argv) * |
881 | argvAlloced); | 880 | argvAlloced); |
882 | } | 881 | } |
883 | globLastArgument(prog, &argc_l, &argvAlloced); | 882 | globLastArgument(prog, &argc_l, &argvAlloced); |
884 | prog->argv[argc_l] = buf; | 883 | prog->argv[argc_l] = buf; |
@@ -900,9 +899,9 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi | |||
900 | case '>': /* redirections */ | 899 | case '>': /* redirections */ |
901 | case '<': | 900 | case '<': |
902 | i = prog->numRedirections++; | 901 | i = prog->numRedirections++; |
903 | prog->redirections = realloc(prog->redirections, | 902 | prog->redirections = xrealloc(prog->redirections, |
904 | sizeof(*prog->redirections) * | 903 | sizeof(*prog->redirections) * |
905 | (i + 1)); | 904 | (i + 1)); |
906 | 905 | ||
907 | prog->redirections[i].fd = -1; | 906 | prog->redirections[i].fd = -1; |
908 | if (buf != prog->argv[argc_l]) { | 907 | if (buf != prog->argv[argc_l]) { |
@@ -969,8 +968,8 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi | |||
969 | 968 | ||
970 | /* and start the next */ | 969 | /* and start the next */ |
971 | job->numProgs++; | 970 | job->numProgs++; |
972 | job->progs = realloc(job->progs, | 971 | job->progs = xrealloc(job->progs, |
973 | sizeof(*job->progs) * job->numProgs); | 972 | sizeof(*job->progs) * job->numProgs); |
974 | prog = job->progs + (job->numProgs - 1); | 973 | prog = job->progs + (job->numProgs - 1); |
975 | prog->numRedirections = 0; | 974 | prog->numRedirections = 0; |
976 | prog->redirections = NULL; | 975 | prog->redirections = NULL; |
@@ -1058,7 +1057,7 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi | |||
1058 | while ( (size=fullRead(pipefd[0], charptr1, BUFSIZ-1)) >0) { | 1057 | while ( (size=fullRead(pipefd[0], charptr1, BUFSIZ-1)) >0) { |
1059 | int newSize=src - *commandPtr + size + 1 + strlen(charptr2); | 1058 | int newSize=src - *commandPtr + size + 1 + strlen(charptr2); |
1060 | if (newSize > BUFSIZ) { | 1059 | if (newSize > BUFSIZ) { |
1061 | *commandPtr=realloc(*commandPtr, src - *commandPtr + | 1060 | *commandPtr=xrealloc(*commandPtr, src - *commandPtr + |
1062 | size + 1 + strlen(charptr2)); | 1061 | size + 1 + strlen(charptr2)); |
1063 | } | 1062 | } |
1064 | memcpy(src, charptr1, size); | 1063 | memcpy(src, charptr1, size); |
@@ -1231,10 +1230,10 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1231 | 1230 | ||
1232 | /* add the theJob to the list of running jobs */ | 1231 | /* add the theJob to the list of running jobs */ |
1233 | if (!jobList->head) { | 1232 | if (!jobList->head) { |
1234 | theJob = jobList->head = malloc(sizeof(*theJob)); | 1233 | theJob = jobList->head = xmalloc(sizeof(*theJob)); |
1235 | } else { | 1234 | } else { |
1236 | for (theJob = jobList->head; theJob->next; theJob = theJob->next); | 1235 | for (theJob = jobList->head; theJob->next; theJob = theJob->next); |
1237 | theJob->next = malloc(sizeof(*theJob)); | 1236 | theJob->next = xmalloc(sizeof(*theJob)); |
1238 | theJob = theJob->next; | 1237 | theJob = theJob->next; |
1239 | } | 1238 | } |
1240 | 1239 | ||
@@ -1277,7 +1276,7 @@ static int busy_loop(FILE * input) | |||
1277 | /* save current owner of TTY so we can restore it on exit */ | 1276 | /* save current owner of TTY so we can restore it on exit */ |
1278 | parent_pgrp = tcgetpgrp(0); | 1277 | parent_pgrp = tcgetpgrp(0); |
1279 | 1278 | ||
1280 | command = (char *) calloc(BUFSIZ, sizeof(char)); | 1279 | command = (char *) xcalloc(BUFSIZ, sizeof(char)); |
1281 | 1280 | ||
1282 | /* don't pay any attention to this signal; it just confuses | 1281 | /* don't pay any attention to this signal; it just confuses |
1283 | things and isn't really meant for shells anyway */ | 1282 | things and isn't really meant for shells anyway */ |
@@ -1303,7 +1302,7 @@ static int busy_loop(FILE * input) | |||
1303 | } | 1302 | } |
1304 | else { | 1303 | else { |
1305 | free(command); | 1304 | free(command); |
1306 | command = (char *) calloc(BUFSIZ, sizeof(char)); | 1305 | command = (char *) xcalloc(BUFSIZ, sizeof(char)); |
1307 | nextCommand = NULL; | 1306 | nextCommand = NULL; |
1308 | } | 1307 | } |
1309 | } else { | 1308 | } else { |