diff options
author | jilles <jilles@FreeBSD.org> | 2016-03-02 21:24:46 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2016-03-02 21:24:46 +0000 |
commit | 35834011136a6396cb135c3501633d29fd2caa38 (patch) | |
tree | b67b4fcc0f62769af2e90200123edb647d4d10ee | |
parent | b05c8d148a3d1b4dc751217946557652e8c523a1 (diff) | |
download | FreeBSD-src-35834011136a6396cb135c3501633d29fd2caa38.zip FreeBSD-src-35834011136a6396cb135c3501633d29fd2caa38.tar.gz |
sh: Don't trust that signal descriptions fit within 49 bytes.
-rw-r--r-- | bin/sh/jobs.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index b531231..b5d084c 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -322,8 +322,8 @@ static void showjob(struct job *jp, int mode) { char s[64]; - char statestr[64]; - const char *sigstr; + char statebuf[16]; + const char *statestr, *coredump; struct procstat *ps; struct job *j; int col, curr, i, jobno, prev, procno; @@ -339,9 +339,10 @@ showjob(struct job *jp, int mode) prev = j - jobtab + 1; } #endif + coredump = ""; ps = jp->ps + jp->nprocs - 1; if (jp->state == 0) { - strcpy(statestr, "Running"); + statestr = "Running"; #if JOBS } else if (jp->state == JOBSTOPPED) { while (!WIFSTOPPED(ps->status) && ps > jp->ps) @@ -350,27 +351,25 @@ showjob(struct job *jp, int mode) i = WSTOPSIG(ps->status); else i = -1; - sigstr = strsignal(i); - if (sigstr != NULL) - strcpy(statestr, sigstr); - else - strcpy(statestr, "Suspended"); + statestr = strsignal(i); + if (statestr == NULL) + statestr = "Suspended"; #endif } else if (WIFEXITED(ps->status)) { if (WEXITSTATUS(ps->status) == 0) - strcpy(statestr, "Done"); - else - fmtstr(statestr, 64, "Done(%d)", + statestr = "Done"; + else { + fmtstr(statebuf, sizeof(statebuf), "Done(%d)", WEXITSTATUS(ps->status)); + statestr = statebuf; + } } else { i = WTERMSIG(ps->status); - sigstr = strsignal(i); - if (sigstr != NULL) - strcpy(statestr, sigstr); - else - strcpy(statestr, "Unknown signal"); + statestr = strsignal(i); + if (statestr == NULL) + statestr = "Unknown signal"; if (WCOREDUMP(ps->status)) - strcat(statestr, " (core dumped)"); + coredump = " (core dumped)"; } for (ps = jp->ps ; procno > 0 ; ps++, procno--) { /* for each process */ @@ -399,7 +398,8 @@ showjob(struct job *jp, int mode) } if (ps == jp->ps) { out1str(statestr); - col += strlen(statestr); + out1str(coredump); + col += strlen(statestr) + strlen(coredump); } do { out1c(' '); |