tuxera / ntfs-3g

NTFS-3G Safe Read/Write NTFS Driver
https://www.tuxera.com/company/open-source
GNU General Public License v2.0
1.01k stars 149 forks source link

Check if val is NULL before strdup(val) #49

Closed liujinbao1 closed 2 years ago

liujinbao1 commented 2 years ago

HELLO, In the following location of ntfs-3g_common.c/parse_mount_options, val cannot be NULL, but null may be 0

case OPT_USERMAPPING :
  ctx->usermap_path = strdup(val);
  if (!ctx->usermap_path) {
                             ntfs_log_error("no more memory to store'usermapping' option.\n");
                             goto err_exit;
                          }
                          break;

Can we judge null like the following? Or do you have another way?

case OPT_USERMAPPING :
    if(val)
    {
      ctx->usermap_path = strdup(val);
      if (!ctx->usermap_path) 
      {
        ntfs_log_error("no more memory to store'usermapping' option.\n");
        goto err_exit;
      }
    }
    break;

Thank you!

jpandre commented 2 years ago

I would rather check val[0] in missing_option_value() and return a significant error.

liujinbao1 commented 2 years ago

OK, thank you.