dtsr: Coverity fixes for string buffer issues
[oweals/cde.git] / cde / programs / dtsr / tomita.c
index 2611279c91ec9d83e9a64c89fee32c9babad3bff..c165a365475bdbc38da0dcec8f2fdae271feddb9 100644 (file)
@@ -1,3 +1,25 @@
+/*
+ * CDE - Common Desktop Environment
+ *
+ * Copyright (c) 1993-2012, The Open Group. All rights reserved.
+ *
+ * These libraries and programs are free software; you can
+ * redistribute them and/or modify them under the terms of the GNU
+ * Lesser General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * These libraries and programs are distributed in the hope that
+ * they will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with these librararies and programs; if not, write
+ * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301 USA
+ */
 /*
  *   COMPONENT_NAME: austext
  *
@@ -67,6 +89,7 @@
 #include <signal.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <stdlib.h>
 
 #define PRINT_MESSAGES \
     { puts (DtSearchGetMessages()); DtSearchFreeMessages(); }
@@ -174,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);
@@ -224,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 */
@@ -400,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 */
 
@@ -449,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';
 
@@ -478,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';
 
@@ -655,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;
     }
@@ -679,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
@@ -896,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() */