Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit 39593a7

Browse files
authored
Merge pull request #55 from kazumi007/fix-getrlimit-res-invalid
Fix getrlimit() to return EINVAL if a resource value isn't valid.
2 parents fdfb667 + 6869b5f commit 39593a7

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/proc/process.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,7 @@ DEFINE_SYSCALL(gettid)
294294
return do_gettid();
295295
}
296296

297-
DEFINE_SYSCALL(getrlimit, int, l_resource, gaddr_t, rl_ptr)
298-
{
299-
struct rlimit rl;
300-
struct l_rlimit l_rl;
301-
297+
int linux_to_darwin_rlimopts(int l_resource) {
302298
int resource = 0;
303299
switch (l_resource) {
304300
case LINUX_RLIMIT_CPU: resource = RLIMIT_CPU; break;
@@ -312,6 +308,19 @@ DEFINE_SYSCALL(getrlimit, int, l_resource, gaddr_t, rl_ptr)
312308
case LINUX_RLIMIT_MEMLOCK: resource = RLIMIT_MEMLOCK; break;
313309
case LINUX_RLIMIT_AS: resource = RLIMIT_AS; break;
314310
}
311+
return resource;
312+
}
313+
314+
DEFINE_SYSCALL(getrlimit, int, l_resource, gaddr_t, rl_ptr)
315+
{
316+
struct rlimit rl;
317+
struct l_rlimit l_rl;
318+
319+
if (l_resource >= LINUX_RLIM_NLIMITS) {
320+
return -LINUX_EINVAL;
321+
}
322+
323+
int resource = linux_to_darwin_rlimopts(l_resource);
315324

316325
int r = syswrap(getrlimit(resource, &rl));
317326
if (r < 0)

0 commit comments

Comments
 (0)