File CVE-2018-1126.patch of Package procps.30263
---
proc/alloc.c | 20 ++++++++++++--------
proc/alloc.h | 4 ++--
2 files changed, 14 insertions(+), 10 deletions(-)
--- proc/alloc.c
+++ proc/alloc.c 2018-06-05 13:04:30.091933526 +0000
@@ -37,14 +37,14 @@ static void xdefault_error(const char *r
message_fn xalloc_err_handler = xdefault_error;
-void *xcalloc(unsigned int size) {
+void *xcalloc(size_t size) {
void * p;
if (size == 0)
++size;
p = calloc(1, size);
if (!p) {
- xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
+ xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return p;
@@ -57,20 +57,20 @@ void *xmalloc(size_t size) {
++size;
p = malloc(size);
if (!p) {
- xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
+ xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return(p);
}
-void *xrealloc(void *oldp, unsigned int size) {
+void *xrealloc(void *oldp, size_t size) {
void *p;
if (size == 0)
++size;
p = realloc(oldp, size);
if (!p) {
- xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
+ xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
return(p);
@@ -80,13 +80,17 @@ char *xstrdup(const char *str) {
char *p = NULL;
if (str) {
- unsigned int size = strlen(str) + 1;
+ size_t size = strlen(str) + 1;
+ if (size < 1) {
+ xalloc_err_handler("%s refused to allocate %zu bytes of memory", __func__, size);
+ exit(EXIT_FAILURE);
+ }
p = malloc(size);
if (!p) {
- xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
+ xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
exit(EXIT_FAILURE);
}
- strcpy(p, str);
+ memcpy(p, str, size);
}
return(p);
}
--- proc/alloc.h
+++ proc/alloc.h 2018-06-05 13:04:30.091933526 +0000
@@ -8,9 +8,9 @@ EXTERN_C_BEGIN
/* change xalloc_err_handler to override the default fprintf(stderr... */
extern message_fn xalloc_err_handler;
-extern void *xcalloc(unsigned int size) MALLOC;
+extern void *xcalloc(size_t size) MALLOC;
extern void *xmalloc(size_t size) MALLOC;
-extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
+extern void *xrealloc(void *oldp, size_t size) MALLOC;
extern char *xstrdup(const char *str) MALLOC;
EXTERN_C_END