From 920db6d3935c86aff1b4fd0096ce6b5e3605d20d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Mon, 19 Jan 2015 22:49:10 +0100 Subject: libc: Avoid redundant setting of ENOMEM Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/dirent/opendir.c | 2 +- libc/stdlib/_atexit.c | 2 +- libc/stdlib/malloc-simple/alloc.c | 4 +++- libc/stdlib/malloc-standard/malloc.c | 2 +- libc/stdlib/malloc-standard/malloc.h | 2 +- libc/stdlib/setenv.c | 4 ++-- libc/stdlib/unix_grantpt.c | 2 +- libc/string/_collate.c | 4 ++-- 8 files changed, 12 insertions(+), 10 deletions(-) (limited to 'libc') diff --git a/libc/misc/dirent/opendir.c b/libc/misc/dirent/opendir.c index 66a5cc9e9..8af00f88c 100644 --- a/libc/misc/dirent/opendir.c +++ b/libc/misc/dirent/opendir.c @@ -110,7 +110,7 @@ DIR *opendir(const char *name) if (!ptr) { close_not_cancel_no_status(fd); - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ } return ptr; } diff --git a/libc/stdlib/_atexit.c b/libc/stdlib/_atexit.c index ef6772fb5..3faa9f05f 100644 --- a/libc/stdlib/_atexit.c +++ b/libc/stdlib/_atexit.c @@ -257,7 +257,7 @@ struct exit_function attribute_hidden *__new_exitfn(void) efp = realloc(__exit_function_table, (__exit_slots+20)*sizeof(struct exit_function)); if (efp == NULL) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ goto DONE; } __exit_function_table = efp; diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c index 14f384632..a3c068a5b 100644 --- a/libc/stdlib/malloc-simple/alloc.c +++ b/libc/stdlib/malloc-simple/alloc.c @@ -42,8 +42,10 @@ void *malloc(size_t size) result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE, MMAP_FLAGS, 0, 0); - if (result == MAP_FAILED) + if (result == MAP_FAILED) { + __set_errno(ENOMEM); return 0; + } * (size_t *) result = size; return(result + sizeof(size_t)); } diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c index 3253ebda6..2abb5bbdd 100644 --- a/libc/stdlib/malloc-standard/malloc.c +++ b/libc/stdlib/malloc-standard/malloc.c @@ -744,7 +744,7 @@ static void* __malloc_alloc(size_t nb, mstate av) } /* catch all failure paths */ - errno = ENOMEM; + __set_errno(ENOMEM); return 0; } diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h index d945627c6..1a4cc5a62 100644 --- a/libc/stdlib/malloc-standard/malloc.h +++ b/libc/stdlib/malloc-standard/malloc.h @@ -512,7 +512,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #define checked_request2size(req, sz) \ if (REQUEST_OUT_OF_RANGE(req)) { \ - errno = ENOMEM; \ + __set_errno(ENOMEM); \ return 0; \ } \ (sz) = request2size(req); diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index 00e3f3d65..f3b53b6c5 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -76,7 +76,7 @@ static int __add_to_environ(const char *name, const char *value, /* We allocated this space; we can extend it. */ new_environ = realloc(last_environ, (size + 2) * sizeof(char *)); if (new_environ == NULL) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ goto DONE; } if (__environ != last_environ) { @@ -97,7 +97,7 @@ static int __add_to_environ(const char *name, const char *value, var_val = malloc(namelen + 1 + vallen); if (var_val == NULL) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ goto DONE; } memcpy(var_val, name, namelen); diff --git a/libc/stdlib/unix_grantpt.c b/libc/stdlib/unix_grantpt.c index 5dbb7f52d..66c18c0ed 100644 --- a/libc/stdlib/unix_grantpt.c +++ b/libc/stdlib/unix_grantpt.c @@ -68,7 +68,7 @@ pts_name (int fd, char **pts, size_t buf_len) if (! new_buf) { rv = -1; - errno = ENOMEM; + /* __set_errno(ENOMEM); */ break; } buf = new_buf; diff --git a/libc/string/_collate.c b/libc/string/_collate.c index 2ebfb9317..93501b85e 100644 --- a/libc/string/_collate.c +++ b/libc/string/_collate.c @@ -367,7 +367,7 @@ static void next_weight(col_state_t *cs, int pass __LOCALE_PARAM ) if (cs->back_buf == cs->ibb) { /* was using internal buffer */ cs->bp = malloc(cs->bb_size + 128); if (!cs->bp) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ #ifdef __UCLIBC_MJN3_ONLY__ #warning what to do here? #endif @@ -379,7 +379,7 @@ static void next_weight(col_state_t *cs, int pass __LOCALE_PARAM ) } else { cs->bp = realloc(cs->back_buf, cs->bb_size + 128); if (!cs->bp) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ #ifdef __UCLIBC_MJN3_ONLY__ #warning what to do here? #endif -- cgit v1.2.3 From 217f0a86c07beae6a27d422b5f46ee853f3a447a Mon Sep 17 00:00:00 2001 From: Xishi Qiu Date: Tue, 4 Nov 2014 19:26:28 +0800 Subject: add argument check in setenv() setenv() in glibc/eglibc will check the argument, like this, ... if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { __set_errno (EINVAL); return -1; } ... So add argument check in uclibc's setenv() too. Signed-off-by: Xishi Qiu Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/setenv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index f3b53b6c5..ecc302536 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -41,7 +41,7 @@ static char **last_environ; to reuse values once generated for a `setenv' call since we can never free the strings. [in uclibc, we do not] */ static int __add_to_environ(const char *name, const char *value, - int replace) + int replace) { register char **ep; register size_t size; @@ -116,6 +116,11 @@ static int __add_to_environ(const char *name, const char *value, int setenv(const char *name, const char *value, int replace) { + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { + __set_errno(EINVAL); + return -1; + } + /* NB: setenv("VAR", NULL, 1) inserts "VAR=" string */ return __add_to_environ(name, value ? value : "", replace); } -- cgit v1.2.3 From e55f589191162eb40f44696c77e569049313d381 Mon Sep 17 00:00:00 2001 From: Wang Yufen Date: Tue, 11 Nov 2014 15:59:11 +0800 Subject: add argument check in mknod mknod() in glibc/eglibc will check the argument, like this, ... if (k_dev != dev) { __set_errno (EINVAL); return -1; } ... So add argument check in uclibc's mknod() too. Signed-off-by: Wang Yufen Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/mknod.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/mknod.c b/libc/sysdeps/linux/common/mknod.c index 416cab6d0..e0c54e6e3 100644 --- a/libc/sysdeps/linux/common/mknod.c +++ b/libc/sysdeps/linux/common/mknod.c @@ -24,6 +24,10 @@ int mknod(const char *path, mode_t mode, dev_t dev) /* We must convert the value to dev_t type used by the kernel. */ k_dev = (dev) & ((1ULL << 32) - 1); + if (k_dev != dev) { + __set_errno(EINVAL); + return -1; + } return INLINE_SYSCALL(mknod, 3, path, mode, (unsigned int)k_dev); } #endif -- cgit v1.2.3 From d88e1855ff2828fbad0335fc8e06dd295e1c1130 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sat, 24 Jan 2015 20:50:02 +0100 Subject: libc: ppc64 etc: Fix sync_file_range Fix copy'n paste error for ppc64 and other sync_file_range2 arches Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/sync_file_range.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/sync_file_range.c b/libc/sysdeps/linux/common/sync_file_range.c index 8d4ed9210..267b922eb 100644 --- a/libc/sysdeps/linux/common/sync_file_range.c +++ b/libc/sysdeps/linux/common/sync_file_range.c @@ -23,10 +23,13 @@ static int __NC(sync_file_range)(int fd, off64_t offset, off64_t nbytes, unsigned int flags) { # if defined __powerpc__ && __WORDSIZE == 64 - return INLINE_SYSCALL(sync_file_range, 4, fd, offset, nbytes, flags); + return INLINE_SYSCALL(sync_file_range, 4, fd, flags, offset, nbytes); # elif defined __mips__ && _MIPS_SIM == _ABIO32 return INLINE_SYSCALL(sync_file_range, 7, fd, 0, OFF64_HI_LO(offset), OFF64_HI_LO(nbytes), flags); +# elif defined __NR_sync_file_range2 + return INLINE_SYSCALL(sync_file_range, 6, fd, flags + OFF64_HI_LO(offset), OFF64_HI_LO(nbytes)); # else return INLINE_SYSCALL(sync_file_range, 6, fd, OFF64_HI_LO(offset), OFF64_HI_LO(nbytes), flags); -- cgit v1.2.3 From 92de8a5f6ffb1ff9f7183fd08d872aa098b75ae2 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Mon, 26 Jan 2015 16:50:29 +0100 Subject: libc: sync_file_range missing comma Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/sync_file_range.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/sync_file_range.c b/libc/sysdeps/linux/common/sync_file_range.c index 267b922eb..6cd7e94d6 100644 --- a/libc/sysdeps/linux/common/sync_file_range.c +++ b/libc/sysdeps/linux/common/sync_file_range.c @@ -28,7 +28,7 @@ static int __NC(sync_file_range)(int fd, off64_t offset, off64_t nbytes, unsigne return INLINE_SYSCALL(sync_file_range, 7, fd, 0, OFF64_HI_LO(offset), OFF64_HI_LO(nbytes), flags); # elif defined __NR_sync_file_range2 - return INLINE_SYSCALL(sync_file_range, 6, fd, flags + return INLINE_SYSCALL(sync_file_range, 6, fd, flags, OFF64_HI_LO(offset), OFF64_HI_LO(nbytes)); # else return INLINE_SYSCALL(sync_file_range, 6, fd, -- cgit v1.2.3