< prev index next >

agent/src/os/bsd/libproc_impl.c

Print this page
rev 8113 : 8076475: Misuses of strncpy/strncat
Summary: Various small fixes around strncpy and strncat
Reviewed-by: dsamersoff

@@ -213,11 +213,16 @@
   if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
     print_debug("can't allocate memory for lib_info\n");
     return NULL;
   }
 
-  strncpy(newlib->name, libname, sizeof(newlib->name));
+  if (strlen(libname) >= sizeof(newlib->name)) {
+    print_debug("libname %s too long\n", libname);
+    return NULL;
+  }
+  strcpy(newlib->name, libname);
+
   newlib->base = base;
 
   if (fd == -1) {
     if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
       print_debug("can't open shared object %s\n", newlib->name);
< prev index next >