If path is null and the memory is allocated by us then if size < len
we exit the call without freeing the memory. We solve this by moving the
check for sizer earlier.
Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@upb.ro>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
size_t len = strlen(t->t_cwd) + 1;
int error;
+ if (size < len) {
+ error = ERANGE;
+ goto out_errno;
+ }
+
if (!path) {
if (!size)
size = len;
}
}
- if (size < len) {
- error = ERANGE;
- goto out_errno;
- }
-
memcpy(path, t->t_cwd, len);
trace_vfs_getcwd_ret(path);
return path;