Browse Source

Add checks for functions that may fail

Georgi Chorbadzhiyski 7 years ago
parent
commit
6e34110ff1
2 changed files with 13 additions and 7 deletions
  1. 5
    5
      notify.c
  2. 8
    2
      process.c

+ 5
- 5
notify.c View File

@@ -54,10 +54,10 @@ static void *do_notify(void *in) {
54 54
 		int e = 0;
55 55
 		unsigned int i, r;
56 56
 		char **env = calloc(32, sizeof(char *));
57
-		asprintf(&env[e++], "_TS=%ld"			, time(NULL));
58
-		asprintf(&env[e++], "_IDENT=%s"			, shared->ident);
59
-		asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id);
60
-		asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text);
57
+		if (asprintf(&env[e++], "_TS=%ld"			, time(NULL)) < 0) exit(EXIT_FAILURE);
58
+		if (asprintf(&env[e++], "_IDENT=%s"			, shared->ident) < 0) exit(EXIT_FAILURE);
59
+		if (asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
60
+		if (asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text) < 0) exit(EXIT_FAILURE);
61 61
 		r = strlen(shared->msg_id);
62 62
 		for (i=0; i<r; i++) {
63 63
 			if (isalpha(shared->msg_id[i]))
@@ -65,7 +65,7 @@ static void *do_notify(void *in) {
65 65
 			if (shared->msg_id[i] == '_')
66 66
 				shared->msg_id[i] = ' ';
67 67
 		}
68
-		asprintf(&env[e++], "_MESSAGE_MSG=%s"	, shared->msg_id);
68
+		if (asprintf(&env[e++], "_MESSAGE_MSG=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
69 69
 		execve(args[0], args, env);
70 70
 		// We reach here only if there is an error.
71 71
 		fprintf(stderr, "execve('%s') failed: %s!\n", args[0], strerror(errno));

+ 8
- 2
process.c View File

@@ -258,7 +258,10 @@ static inline void output_write(struct ts *ts, uint8_t *data, unsigned int data_
258 258
 	if (ts->no_output_on_error && !ts->camd.key->is_valid_cw)
259 259
 		return;
260 260
 	if (!ts->rtp_output) {
261
-		write(ts->output.fd, data, data_size);
261
+		if (write(ts->output.fd, data, data_size) < 0) {
262
+			perror("write(output_fd)");
263
+			return;
264
+		}
262 265
 	} else {
263 266
 		struct iovec iov[2];
264 267
 		uint8_t rtp_header[12];
@@ -286,7 +289,10 @@ static inline void output_write(struct ts *ts, uint8_t *data, unsigned int data_
286 289
 		iov[1].iov_base = data;
287 290
 		iov[1].iov_len  = data_size;
288 291
 
289
-		writev(ts->output.fd, iov, 2);
292
+		if (writev(ts->output.fd, iov, 2) < 0) {
293
+			perror("writev(output_fd)");
294
+			return;
295
+		}
290 296
 	}
291 297
 }
292 298
 

Loading…
Cancel
Save