| 1 | Sun Feb 4 19:44:00 UTC 2007 Nathan Baum <nathan_baum@btinternet.com> |
|---|
| 2 | * hardened-chopstr |
|---|
| 3 | diff -rN -c old-vanilla/src/strutil.c new-vanilla/src/strutil.c |
|---|
| 4 | *** old-vanilla/src/strutil.c 2007-02-04 19:45:18.000000000 +0000 |
|---|
| 5 | --- new-vanilla/src/strutil.c 2007-02-04 19:45:18.000000000 +0000 |
|---|
| 6 | *************** |
|---|
| 7 | *** 77,82 **** |
|---|
| 8 | --- 77,83 ---- |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | /** Return the string chopped at lim characters. |
|---|
| 12 | + * lim is clipped to (0 .. BUFFER_LEN] |
|---|
| 13 | * \param str string to chop. |
|---|
| 14 | * \param lim character at which to chop the string. |
|---|
| 15 | * \return statically allocated buffer with chopped string. |
|---|
| 16 | *************** |
|---|
| 17 | *** 87,92 **** |
|---|
| 18 | --- 88,95 ---- |
|---|
| 19 | static char tbuf1[BUFFER_LEN]; |
|---|
| 20 | if (strlen(str) <= lim) |
|---|
| 21 | return (char *) str; |
|---|
| 22 | + if (lim >= BUFFER_LEN) |
|---|
| 23 | + lim = BUFFER_LEN - 1; |
|---|
| 24 | strncpy(tbuf1, str, lim); |
|---|
| 25 | tbuf1[lim] = '\0'; |
|---|
| 26 | return tbuf1; |
|---|