zfs/cmd/zpool
Matthew Ahrens 8a969f3e2d Read past end of argv array in zpool_do_import()
`zpool_do_import()` passes `argv[0]`, (optionally) `argv[1]`, and
`pool_specified` to `import_pools()`.  If `pool_specified==FALSE`, the
`argv[]` arguments are not used.  However, these values may be off the
end of the `argv[]` array, so loading them could dereference unmapped
memory.  This error is reported by the asan build:

```
=================================================================
==6003==ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 8 at 0x6030000004a8 thread T0
    #0 0x562a078b50eb in zpool_do_import zpool_main.c:3796
    #1 0x562a078858c5 in main zpool_main.c:10709
    #2 0x7f5115231bf6 in __libc_start_main
    #3 0x562a07885eb9 in _start

0x6030000004a8 is located 0 bytes to the right of 24-byte region
allocated by thread T0 here:
    #0 0x7f5116ac6b40 in __interceptor_malloc
    #1 0x562a07885770 in main zpool_main.c:10699
    #2 0x7f5115231bf6 in __libc_start_main
```

This commit passes NULL for these arguments if they are off the end
of the `argv[]` array.

Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #12339
2021-09-14 13:08:53 -07:00
..
compatibility.d Add compatibility file sets (ZoL 0.6.1, 0.6.4, OpenZFS 2.1) 2021-04-07 13:24:08 -07:00
os FreeBSD boot code reminder after zpool upgrade 2021-06-09 13:05:34 -07:00
zpool.d Turn checkbashisms into a make target 2021-06-09 13:05:34 -07:00
.gitignore Add .gitignore files to exclude build products 2010-01-08 11:35:17 -08:00
Makefile.am Turn shellcheck into a normal make target. Fix new files it caught 2021-06-09 13:05:34 -07:00
zpool_iter.c zpool: vdev_run_cmd(): don't free undefined pointers 2021-05-10 12:21:12 -07:00
zpool_main.c Read past end of argv array in zpool_do_import() 2021-09-14 13:08:53 -07:00
zpool_util.c OpenZFS restructuring - zpool 2019-09-30 12:16:06 -07:00
zpool_util.h FreeBSD boot code reminder after zpool upgrade 2021-06-09 13:05:34 -07:00
zpool_vdev.c Fix various typos 2021-04-07 13:27:11 -07:00