Replace unsafe use of gets()
[openafs.git] / src / tviced / state_analyzer.c
index 1919030..d3bfd38 100644 (file)
@@ -17,8 +17,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <stdio.h>
 #include <errno.h>
@@ -239,21 +237,16 @@ static struct {
     byte cb_valid;
 } cb_cursor;
 
-static struct {
-    void ** cursor;
-} cb_cache;
-
 static void
 usage(char * prog)
 {
-    fprintf(stderr, "usage: %s [<state dump file>]\n");
+    fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
 }
 
 int
 main(int argc, char ** argv)
 {
     banner();
-
     if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
        usage(argv[0]);
        return 1;
@@ -265,7 +258,7 @@ main(int argc, char ** argv)
        if (openFile(argv[1]))
            return 1;
     } else {
-       if (openFile(AFSDIR_SERVER_FSSTATE_FILEPATH))
+       if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH))
            return 1;
     }
 
@@ -304,7 +297,7 @@ openFile(char * path)
        goto done;
     }
 
-    printf("mapped %d bytes at 0x%x\n", map_len, map);
+    printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map);
 
  done:
     if (ret) {
@@ -375,7 +368,7 @@ prompt(void)
                fprintf(stderr, "prompt state broken; aborting\n");
                return;
            }
-           gets(input);
+           fgets(input, 256, stdin);
 
            if (!strcmp(input, "")) {
                /* repeat last command */
@@ -744,8 +737,8 @@ print_cb_help(void)
     do { \
         char * _p = (char *)addr; \
         char * _m = (char *)map; \
-        printf("loading structure from address 0x%x (offset %u)\n", \
-               addr, _p-_m); \
+        printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \
+               addr, (long)(_p-_m)); \
     } while (0)
 
 /* structs */
@@ -786,8 +779,8 @@ print_cb_help(void)
 /* time */
 #define DPFT(T, name, var) \
     do { \
-        char * last; \
-        printf(T "%s = \"%s\"\n", name, strtok_r(ctime(&(var)), "\r\n", &last)); \
+        time_t t = var; \
+        printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
     } while(0)
 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
@@ -1285,8 +1278,9 @@ dump_he_hdr(void)
 static void
 dump_he_entry(void)
 {
+    char hoststr[16];
     DPFSO0("hostDiskEntry");
-    DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
+    DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr));
     DPFV1("port", "u", he_cursor.he.port);
     DPFX1("hostFlags", he_cursor.he.hostFlags);
     DPFV1("Console", "u", he_cursor.he.Console);
@@ -1314,6 +1308,7 @@ dump_he_interfaces(void)
     char temp_str[40];
     struct Interface * ifp;
     int len, i;
+    char hoststr[16];
 
     if (!he_cursor.hdr.interfaces)
        return;
@@ -1332,7 +1327,7 @@ dump_he_interfaces(void)
     for (i = 0; i < he_cursor.hdr.interfaces; i++) {
        snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
        DPFSO1(temp_str);
-       DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
+       DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr));
        DPFV2("port", "u", ifp->interface[i].port);
        DPFSC1;
     }
@@ -1348,7 +1343,6 @@ dump_he_interfaces(void)
 static void
 dump_he_hcps(void)
 {
-    char temp_str[40];
     afs_int32 * hcps;
     int len, i;
 
@@ -1436,14 +1430,13 @@ hexdump_map(afs_uint32 offset, afs_uint32 len)
 {
     int i;
     unsigned char * p = (unsigned char *)map;
-    afs_uint32 c32;
 
     if (!len)
        return;
 
     if ((offset + len) > map_len) {
-       fprintf(stderr, "offset + length exceeds memory map size (%u > %u)\n",
-               offset+len, map_len);
+       fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
+               offset+len, (unsigned long)map_len);
        return;
     }
 
@@ -1607,8 +1600,6 @@ get_cb_timeout_hdr(void)
 static int
 get_cb_timeout(void)
 {
-    char * buf;
-
     if (hdrs.timeout)
        return 0;
 
@@ -1660,8 +1651,6 @@ get_cb_fehash_hdr(void)
 static int
 get_cb_fehash(void)
 {
-    char * buf;
-
     if (hdrs.fehash)
        return 0;
 
@@ -1827,6 +1816,12 @@ get_fe(afs_uint32 idx)
 static int
 get_fe_hdr(void)
 {
+    if (!fe_cursor.cursor) {
+        if(get_fe(fe_cursor.idx)) {
+           return 1;
+        }
+    }
+    
     memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
     fe_cursor.hdr_valid = 1;
     return 0;
@@ -1857,7 +1852,6 @@ get_fe_entry(void)
 static int
 get_cb(afs_uint32 idx)
 {
-    int i;
     char * p;
 
     if (get_fe(fe_cursor.idx))
@@ -1891,6 +1885,7 @@ get_cb_entry(void)
     return 0;
 }
 
+#if 0
 static int
 find_he_by_index(afs_uint32 idx)
 {
@@ -1915,6 +1910,7 @@ find_he_by_index(afs_uint32 idx)
     }
     return 1;
 }
+#endif
 
 static int
 find_fe_by_index(afs_uint32 idx)