dtsr: Coverity fixes for string buffer issues
[oweals/cde.git] / cde / programs / dtsr / tomita.c
index d2db3027eae1c5564c17a037e2e0bf93f2b35adc..c165a365475bdbc38da0dcec8f2fdae271feddb9 100644 (file)
@@ -89,6 +89,7 @@
 #include <signal.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <stdlib.h>
 
 #define PRINT_MESSAGES \
     { puts (DtSearchGetMessages()); DtSearchFreeMessages(); }
@@ -196,7 +197,7 @@ static int      change_database (char *newname)
        return FALSE;
 
     /* If browsing, tell user his options */
-    fprintf (aa_stderr,  catgets(dtsearch_catd, MS_tomita, 5,
+    fprintf (aa_stderr, "%s", catgets(dtsearch_catd, MS_tomita, 5,
        "Available choices are:") );
     for (db = usrblk.dblist; db != NULL; db = db->link)
        fprintf (aa_stderr, "   '%s'", db->name);
@@ -246,7 +247,7 @@ static int      parse_infbuf (char *infbuf)
            return FALSE;
        }
 
-    strcpy (parsed_dbname, ptr);
+    snprintf(parsed_dbname, sizeof(parsed_dbname), "%s", ptr);
     parsed_dblk = usrblk.dblk;
 
     /* Hop over to beginning of 2nd token */
@@ -422,7 +423,7 @@ static int      browser (void)
                continue;
 
            default:
-               printf (catgets(dtsearch_catd, MS_tomita, 16, "...what?\n"));
+               printf ("%s", catgets(dtsearch_catd, MS_tomita, 16, "...what?\n"));
                continue;
        }       /* end switch */
 
@@ -471,11 +472,14 @@ DISPLAY_RECORD:
            if (pausing && *ptr == '\n') {
                if (++pause_counter >= PAUSE_ROWS) {
                    /* Msg 21 is used in two places */
-                   printf ( catgets(dtsearch_catd, MS_tomita, 21,
+                   printf ( "%s", catgets(dtsearch_catd, MS_tomita, 21,
                        "\n...push ENTER to continue... ") );
 
                    *userbuf = '\0';
-                   fgets (userbuf, sizeof (userbuf), stdin);
+                   if(NULL == fgets (userbuf, sizeof (userbuf), stdin)) {
+                       fprintf(stderr, "Failed to read from stdin\n");
+                       exit(EXIT_FAILURE);    
+                   }
                    if (strlen(userbuf) && userbuf[strlen(userbuf)-1] == '\n')
                      userbuf[strlen(userbuf)-1] = '\0';
 
@@ -500,12 +504,16 @@ DISPLAY_RECORD:
                    if (pausing && *ptr == '\n')
                        if (++pause_counter >= PAUSE_ROWS) {
                            /* Msg 21 is used in two places */
-                           printf ( catgets(dtsearch_catd, MS_tomita, 21,
+                           printf ( "%s", catgets(dtsearch_catd, MS_tomita, 21,
                                "\n...push ENTER to continue... ") );
 
                            *userbuf = '\0';
-                           fgets (userbuf, sizeof (userbuf), stdin);
-                           if (strlen(userbuf) &&
+                           if(NULL == fgets (userbuf, sizeof (userbuf), stdin)) {
+                               fprintf(stderr, "Failed to read from stdin 2\n");
+                               exit(EXIT_FAILURE);    
+                           }
+                       
+                           if (strlen(userbuf) &&
                                userbuf[strlen(userbuf)-1] == '\n')
                              userbuf[strlen(userbuf)-1] = '\0';
 
@@ -677,7 +685,10 @@ static void     deleter (char *infname)
     "If you are sure you are ready to start deleting, enter 'y' now... ") ,
            infname, OE_prodname);
 
-       fgets (buf, sizeof(buf)-1, stdin);
+       if(NULL == fgets (buf, sizeof(buf)-1, stdin)) {
+               fprintf(stderr, "no input\n");
+               return;
+       }
        if (tolower (*buf) != 'y')
            return;
     }
@@ -701,7 +712,9 @@ static void     deleter (char *infname)
     signal (SIGQUIT, kill_delete);
     signal (SIGTRAP, kill_delete);
     signal (SIGTERM, kill_delete);
+#ifdef SIGPWR
     signal (SIGPWR, kill_delete);
+#endif
 #ifdef _AIX
     signal (SIGXCPU, kill_delete);     /* cpu time limit exceeded */
     signal (SIGDANGER, kill_delete);   /* imminent paging space
@@ -918,7 +931,7 @@ BAD_ARGS:
 
     usrblk.request = OE_SHUTDOWN;
     Opera_Engine ();
-    printf ( catgets(dtsearch_catd, MS_tomita, 36,
+    printf ( "%s", catgets(dtsearch_catd, MS_tomita, 36,
        "Normal engine shutdown.\n") );
     DtSearchExit (0);
 }  /* main() */