Avoid segfaults by not using snprintf to copy strings.
This commit is contained in:
parent
721119e1db
commit
0b2da467a8
3
lash.c
3
lash.c
@ -1023,7 +1023,8 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi
|
|||||||
|
|
||||||
/* Make some space to hold just the backticked command */
|
/* Make some space to hold just the backticked command */
|
||||||
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
||||||
snprintf(charptr1, 1+ptr-src, src);
|
memcpy(charptr1, src, ptr-src);
|
||||||
|
charptr1[ptr-src] = '\0';
|
||||||
newJob = xmalloc(sizeof(struct job));
|
newJob = xmalloc(sizeof(struct job));
|
||||||
/* Now parse and run the backticked command */
|
/* Now parse and run the backticked command */
|
||||||
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
||||||
|
3
sh.c
3
sh.c
@ -1023,7 +1023,8 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi
|
|||||||
|
|
||||||
/* Make some space to hold just the backticked command */
|
/* Make some space to hold just the backticked command */
|
||||||
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
||||||
snprintf(charptr1, 1+ptr-src, src);
|
memcpy(charptr1, src, ptr-src);
|
||||||
|
charptr1[ptr-src] = '\0';
|
||||||
newJob = xmalloc(sizeof(struct job));
|
newJob = xmalloc(sizeof(struct job));
|
||||||
/* Now parse and run the backticked command */
|
/* Now parse and run the backticked command */
|
||||||
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
||||||
|
@ -1023,7 +1023,8 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi
|
|||||||
|
|
||||||
/* Make some space to hold just the backticked command */
|
/* Make some space to hold just the backticked command */
|
||||||
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
charptr1 = charptr2 = xmalloc(1+ptr-src);
|
||||||
snprintf(charptr1, 1+ptr-src, src);
|
memcpy(charptr1, src, ptr-src);
|
||||||
|
charptr1[ptr-src] = '\0';
|
||||||
newJob = xmalloc(sizeof(struct job));
|
newJob = xmalloc(sizeof(struct job));
|
||||||
/* Now parse and run the backticked command */
|
/* Now parse and run the backticked command */
|
||||||
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
if (!parseCommand(&charptr1, newJob, &njobList, inBg)
|
||||||
|
Loading…
Reference in New Issue
Block a user