| ... | ... |
@@ -17,7 +17,8 @@ |
| 17 | 17 |
#include "inodelist.h" |
| 18 | 18 |
#include "mypcap.h" |
| 19 | 19 |
|
| 20 |
-const int MAX_FDLINK = 10; |
|
| 20 |
+/* dirent.d_name can hold a NAME_MAX-byte name plus its terminator. */ |
|
| 21 |
+const int MAX_FDLINK = 256; |
|
| 21 | 22 |
const int MAX_PID_LENGTH = 20; |
| 22 | 23 |
#define MAX_SIZE 256 |
| 23 | 24 |
|
| ... | ... |
@@ -324,9 +325,11 @@ void _get_info_for_pid(const char *pid) {
|
| 324 | 325 |
if (entry->d_type != DT_LNK) |
| 325 | 326 |
continue; |
| 326 | 327 |
|
| 327 |
- size_t fromlen = dirlen + strlen(entry->d_name) + 1; |
|
| 328 | 328 |
char fromname[10 + MAX_PID_LENGTH + 1 + MAX_FDLINK]; |
| 329 |
- snprintf(fromname, fromlen, "%s/%s", dirname, entry->d_name); |
|
| 329 |
+ int fromlen = snprintf(fromname, sizeof(fromname), "%s/%s", dirname, entry->d_name); |
|
| 330 |
+ if (fromlen < 0 || (size_t)fromlen >= sizeof(fromname)) {
|
|
| 331 |
+ continue; |
|
| 332 |
+ } |
|
| 330 | 333 |
|
| 331 | 334 |
int linklen = 80; |
| 332 | 335 |
char linkname[linklen]; |