diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-14 16:19:00 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-14 16:42:41 -0800 |
commit | c623f10e9acc9033b2df436126799424eb5830b8 (patch) | |
tree | 3b1d880aeda1fb6c08d2e7f196faea75c7218d67 | |
parent | 0ca4db4996abd5e6161567575fe318663d8dd117 (diff) |
Add bounds check to getstr()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | draw.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -252,7 +252,7 @@ DrawArc(DviWidget dw, int x0, int y0, int x1, int y1) /* copy next non-blank string from p to temp, update p */ static const char * -getstr(const char *p, char *temp) +getstr(const char *p, char *temp, size_t temp_size) { while (*p == ' ' || *p == '\t' || *p == '\n') p++; @@ -260,8 +260,13 @@ getstr(const char *p, char *temp) temp[0] = 0; return ((char *) NULL); } - while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0') - *temp++ = *p++; + while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0') { + /* leave room for trailing NIL byte */ + if (temp_size > 1) { + *temp++ = *p++; + temp_size--; + } + } *temp = '\0'; return (p); } @@ -306,10 +311,10 @@ GetSpline(const char *s) while (p && *p) { double x1, y1; - if ((p = getstr(p, d)) == (const char *) NULL) + if ((p = getstr(p, d, sizeof(d))) == (const char *) NULL) break; x1 = x + atof(d); - if ((p = getstr(p, d)) == (const char *) NULL) + if ((p = getstr(p, d, sizeof(d))) == (const char *) NULL) break; y1 = y + atof(d); pt->next = MakePoint(x1, y1); |