btrfs-progs: handle strndup() failure in ino_resolve()
Reported by 'gcc -fanalyzer': cmds/subvolume.c:1078:39: warning: use of possibly-NULL ‘name’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] The failure name duplication is not handled and can potentially lead to a NULL dereference later. Handle the error properly and return template error message. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c6d2d05ee6
commit
8767dda133
|
@ -1138,6 +1138,10 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
|
||||||
|
|
||||||
name = (char *)(ref + 1);
|
name = (char *)(ref + 1);
|
||||||
name = strndup(name, namelen);
|
name = strndup(name, namelen);
|
||||||
|
if (!name) {
|
||||||
|
error_msg(ERROR_MSG_MEMORY, NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* use our cached value */
|
/* use our cached value */
|
||||||
if (dirid == *cache_dirid && *cache_name) {
|
if (dirid == *cache_dirid && *cache_name) {
|
||||||
|
|
Loading…
Reference in New Issue