#define BUF_SIZE (BUFSIZ)
#define HEXA 16
-#define PERM_LEN 5
-#define ADDR_LEN 16
+#define PERM_LEN 4
+#define ADDR_LEN 33
#define STR_ANONY "[anony]"
#define STR_ANONY_LEN 8
-#define STR_FS(length) "%"#length"s"
+#define STRING_FORMAT_SPECIFIER_WITH_MACRO(macro) "%"#macro"s"
+#define STR_FS(macro) STRING_FORMAT_SPECIFIER_WITH_MACRO(macro)
static FILE *outputfile = NULL; ///< global output stream
static FILE *errfile = NULL; ///< global error stream
struct addr_node {
uintptr_t startaddr;
uintptr_t endaddr;
- char perm[PERM_LEN];
+ char perm[PERM_LEN+1];
char *fpath;
struct addr_node *next;
};
int fpath_len, result;
uintptr_t saddr;
uintptr_t eaddr;
- char perm[PERM_LEN];
- char path[PATH_MAX];
- char addr[ADDR_LEN * 2 + 2];
+ char perm[PERM_LEN+1];
+ char path[PATH_MAX+1];
+ char addr[ADDR_LEN+1];
char linebuf[BUF_SIZE];
struct addr_node *head = NULL;
struct addr_node *tail = NULL;
/* parsing the maps to get executable code address */
while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
- memset(path, 0, PATH_MAX);
- result = sscanf(linebuf, STR_FS(sizeof(addr)-1)
- STR_FS(sizeof(perm)-1)
+ memset(path, 0, PATH_MAX+1);
+ result = sscanf(linebuf, STR_FS(ADDR_LEN)
+ STR_FS(PERM_LEN)
"%*s %*s %*s"
- STR_FS(sizeof(path)-1), addr, perm, path);
+ STR_FS(PATH_MAX), addr, perm, path);
if (result < 0)
continue;
- perm[PERM_LEN - 1] = 0;
+ perm[PERM_LEN] = 0;
/* rwxp */
if ((perm[2] == 'x' && path[0] == '/') ||
(perm[1] == 'w' && path[0] != '/')) {
fprintf(errfile, "error : mmap\n");
return NULL;
}
- memcpy(t_node->perm, perm, PERM_LEN);
+ memcpy(t_node->perm, perm, PERM_LEN+1);
t_node->startaddr = saddr;
t_node->endaddr = eaddr;
t_node->fpath = NULL;