Browse Source

Ticket #47835 - Coverity: 12687..12692

12691 - Unbounded source buffer
Description: To solve "Passing string *argv of unknown size to strdup,
which expects a string of a particular size", get ARG_MAX and pass
it to strndup.

Reviewed by [email protected] (Thanks, Rich!)

https://fedorahosted.org/389/ticket/47835
Noriko Hosoi 11 years ago
parent
commit
f25c7f1f98
1 changed files with 5 additions and 2 deletions
  1. 5 2
      ldap/servers/snmp/main.c

+ 5 - 2
ldap/servers/snmp/main.c

@@ -75,6 +75,7 @@ main (int argc, char *argv[]) {
     struct stat         logdir_s;
     pid_t               child_pid;
     FILE                *pid_fp;
+    long                arg_max = 0;
 
     /* Load options */
     while ((--argc > 0) && ((*++argv)[0] == '-')) {
@@ -90,11 +91,13 @@ main (int argc, char *argv[]) {
         }
     }
 
-    if (argc != 1)
+    if ((argc != 1) || (NULL == *argv)) {
         exit_usage();
+    }
 
     /* load config file */
-    if ((config_file = strdup(*argv)) == NULL) {
+    arg_max = sysconf(_SC_ARG_MAX);
+    if ((config_file = strndup(*argv, arg_max)) == NULL) {
         printf("ldap-agent: Memory error loading config file\n");
         exit(1);
     }