vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / pkgs / os-specific / linux / procps-ng / v3-CVE-2023-4016.patch
blob2e260eaf7382a333d055bdd79ee28fbc1ec882f6
1 This is https://gitlab.com/procps-ng/procps/-/commit/2c933ecba3bb1d3041a5a7a53a7b4078a6003413.diff
2 back-ported to procps 3.3.17. That commit changes xmalloc to xcalloc. This patch differs in two ways:
4 * We modify it to change malloc (no x-) to xcalloc instead
5 * We pull in procps-4's definition of xcalloc
7 Alternative considered: Also pull in commits that changed malloc to xmalloc and defined xcalloc.
8 This alternative is rejected because those commits contain many other unrelated changes.
10 diff --git a/ps/parser.c b/ps/parser.c
11 index 4263a1fb..ee9a57d9 100644
12 --- a/ps/parser.c
13 +++ b/ps/parser.c
14 @@ -36,6 +36,14 @@
15 #include "common.h"
16 #include "c.h"
18 +static void *xxcalloc(const size_t nelems, const size_t size)
20 + void *ret = calloc(nelems, size);
21 + if (!ret && size && nelems)
22 + xerrx(EXIT_FAILURE, "cannot allocate %zu bytes", nelems*size);
23 + return ret;
26 #define ARG_GNU 0
27 #define ARG_END 1
28 #define ARG_PGRP 2
29 @@ -184,7 +192,6 @@ static const char *parse_list(const char *arg, const char *(*parse_fn)(char *, s
30 const char *err; /* error code that could or did happen */
31 /*** prepare to operate ***/
32 node = malloc(sizeof(selection_node));
33 - node->u = malloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
34 node->n = 0;
35 buf = strdup(arg);
36 /*** sanity check and count items ***/
37 @@ -205,6 +212,7 @@ static const char *parse_list(const char *arg, const char *(*parse_fn)(char *, s
38 } while (*++walk);
39 if(need_item) goto parse_error;
40 node->n = items;
41 + node->u = xxcalloc(items, sizeof(sel_union));
42 /*** actually parse the list ***/
43 walk = buf;
44 while(items--){
45 @@ -1031,15 +1039,15 @@ static const char *parse_trailing_pids(void){
46 thisarg = ps_argc - 1; /* we must be at the end now */
48 pidnode = malloc(sizeof(selection_node));
49 - pidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
50 + pidnode->u = xxcalloc(i, sizeof(sel_union)); /* waste is insignificant */
51 pidnode->n = 0;
53 grpnode = malloc(sizeof(selection_node));
54 - grpnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
55 + grpnode->u = xxcalloc(i, sizeof(sel_union)); /* waste is insignificant */
56 grpnode->n = 0;
58 sidnode = malloc(sizeof(selection_node));
59 - sidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
60 + sidnode->u = xxcalloc(i, sizeof(sel_union)); /* waste is insignificant */
61 sidnode->n = 0;
63 while(i--){