chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
udev: collect - use snprintf()
[elogind.git]
/
src
/
udev
/
collect
/
collect.c
diff --git
a/src/udev/collect/collect.c
b/src/udev/collect/collect.c
index 80f464aff0040d9e67a34419a2445a8072e70882..3c46e40de11cb84de379957b5163d981aaefa5f8 100644
(file)
--- a/
src/udev/collect/collect.c
+++ b/
src/udev/collect/collect.c
@@
-93,7
+93,7
@@
static int prepare(char *dir, char *filename)
if (stat(dir, &statbuf) < 0)
mkdir(dir, 0700);
if (stat(dir, &statbuf) < 0)
mkdir(dir, 0700);
- s
printf(buf
, "%s/%s", dir, filename);
+ s
nprintf(buf, sizeof(buf)
, "%s/%s", dir, filename);
fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
if (fd < 0)
fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
if (fd < 0)
@@
-141,8
+141,8
@@
static int checkout(int fd)
len = bufsize >> 1;
buf = calloc(1,bufsize + 1);
if (!buf) {
len = bufsize >> 1;
buf = calloc(1,bufsize + 1);
if (!buf) {
- fprintf(stderr, "Out of memory\n");
- return
-1
;
+ fprintf(stderr, "Out of memory
.
\n");
+ return
log_oom()
;
}
memset(buf, ' ', bufsize);
ptr = buf + len;
}
memset(buf, ' ', bufsize);
ptr = buf + len;
@@
-167,7
+167,16
@@
static int checkout(int fd)
if (debug)
fprintf(stderr, "Found word %s\n", word);
him = malloc(sizeof (struct _mate));
if (debug)
fprintf(stderr, "Found word %s\n", word);
him = malloc(sizeof (struct _mate));
+ if (!him) {
+ free(buf);
+ return log_oom();
+ }
him->name = strdup(word);
him->name = strdup(word);
+ if (!him->name) {
+ free(buf);
+ free(him);
+ return log_oom();
+ }
him->state = STATE_OLD;
udev_list_node_append(&him->node, &bunch);
word = NULL;
him->state = STATE_OLD;
udev_list_node_append(&him->node, &bunch);
word = NULL;
@@
-276,7
+285,7
@@
static int missing(int fd)
buf = malloc(bufsize);
if (!buf)
buf = malloc(bufsize);
if (!buf)
- return
-1
;
+ return
log_oom()
;
udev_list_node_foreach(him_node, &bunch) {
struct _mate *him = node_to_mate(him_node);
udev_list_node_foreach(him_node, &bunch) {
struct _mate *him = node_to_mate(him_node);
@@
-291,12
+300,15
@@
static int missing(int fd)
tmpbuf = realloc(buf, bufsize);
if (!tmpbuf) {
free(buf);
tmpbuf = realloc(buf, bufsize);
if (!tmpbuf) {
free(buf);
- return
-1
;
+ return
log_oom()
;
}
buf = tmpbuf;
}
snprintf(buf, strlen(him->name)+2, "%s ", him->name);
}
buf = tmpbuf;
}
snprintf(buf, strlen(him->name)+2, "%s ", him->name);
- write(fd, buf, strlen(buf));
+ if (write(fd, buf, strlen(buf)) < 0) {
+ free(buf);
+ return -1;
+ }
}
}
}
}
@@
-431,7
+443,17
@@
int main(int argc, char **argv)
if (debug)
fprintf(stderr, "ID %s: not in database\n", argv[i]);
him = malloc(sizeof (struct _mate));
if (debug)
fprintf(stderr, "ID %s: not in database\n", argv[i]);
him = malloc(sizeof (struct _mate));
+ if (!him) {
+ ret = ENOMEM;
+ goto out;
+ }
+
him->name = malloc(strlen(argv[i]) + 1);
him->name = malloc(strlen(argv[i]) + 1);
+ if (!him->name) {
+ ret = ENOMEM;
+ goto out;
+ }
+
strcpy(him->name, argv[i]);
him->state = STATE_NONE;
udev_list_node_append(&him->node, &bunch);
strcpy(him->name, argv[i]);
him->state = STATE_NONE;
udev_list_node_append(&him->node, &bunch);