please review: patch to retain device name for dumpdev.

Eric van Gyzen eric at vangyzen.net
Fri Nov 2 14:03:06 UTC 2012


On 11/01/2012 01:48, Alfred Perlstein wrote:
>  /* Registration of dumpers */
>  int
> -set_dumper(struct dumperinfo *di)
> +set_dumper(struct dumperinfo *di, const char *devname)
>  {
>
>      if (di == NULL) {
>          bzero(&dumper, sizeof dumper);
> +        dumpdevname[0] = '\0';
>          return (0);
>      }
>      if (dumper.dumper != NULL)
>          return (EBUSY);
>      dumper = *di;
> +    strlcpy(dumpdevname, devname, sizeof(dumpdevname));
> +    if (strlen(dumpdevname) != strlen(devname)) {

You can use the return value of strlcpy() to test for truncation, and 
save two strlen()s:

         if (strlcpy(...) >= sizeof(dst)) { /* truncated */ }

> + printf("set_dumper: device name truncated from '%s' -> '%s'\n",
> +            devname, dumpdevname);
> +    }
>      return (0);
>  }



More information about the freebsd-hackers mailing list