Skip to content

Commit 1c81f7f

Browse files
Merge pull request #100 from yegorich/fix-return-value-checks
Add missing return value checks
2 parents 5b8145f + 1ce4dc7 commit 1c81f7f

5 files changed

Lines changed: 58 additions & 17 deletions

File tree

cansniffer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,15 @@ void writesettings(char* name){
690690

691691
for (i=0; i < 2048 ;i++) {
692692
sprintf(buf, "<%03X>%c.", i, (is_set(i, ENABLE))?'1':'0');
693-
write(fd, buf, 7);
693+
if (write(fd, buf, 7) < 0)
694+
perror("write");
694695
for (j=0; j<8 ; j++){
695696
sprintf(buf, "%02X", sniftab[i].notch.data[j]);
696-
write(fd, buf, 2);
697+
if (write(fd, buf, 2) < 0)
698+
perror("write");
697699
}
698-
write(fd, "\n", 1);
700+
if (write(fd, "\n", 1) < 0)
701+
perror("write");
699702
/* 7 + 16 + 1 = 24 bytes per entry */
700703
}
701704
close(fd);

jacd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ int main(int argc, char *argv[])
484484
break;
485485
case 'p':
486486
#ifdef _GNU_SOURCE
487-
asprintf(&program_invocation_name, "%s.%s", program_invocation_short_name, optarg);
487+
if (asprintf(&program_invocation_name, "%s.%s", program_invocation_short_name, optarg) < 0)
488+
error(1, errno, "asprintf(program invocation name)");
488489
#else
489490
error(0, 0, "compile with -D_GNU_SOURCE to use -p");
490491
#endif

jsr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ int main(int argc, char **argv)
210210
exit(1);
211211
}
212212
} else {
213-
write(STDOUT_FILENO, buf, ret);
213+
if (write(STDOUT_FILENO, buf, ret) < 0)
214+
error(1, errno, "write(stdout)");
214215
}
215216
}
216217
}

slcan_attach.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,40 @@ int main(int argc, char **argv)
157157

158158
if (speed) {
159159
sprintf(buf, "C\rS%s\r", speed);
160-
write(fd, buf, strlen(buf));
160+
if (write(fd, buf, strlen(buf)) <= 0) {
161+
perror("write");
162+
exit(EXIT_FAILURE);
163+
}
161164
}
162165

163166
if (btr) {
164167
sprintf(buf, "C\rs%s\r", btr);
165-
write(fd, buf, strlen(buf));
168+
if (write(fd, buf, strlen(buf)) <= 0) {
169+
perror("write");
170+
exit(EXIT_FAILURE);
171+
}
166172
}
167173

168174
if (send_read_status_flags) {
169175
sprintf(buf, "F\r");
170-
write(fd, buf, strlen(buf));
176+
if (write(fd, buf, strlen(buf)) <= 0) {
177+
perror("write");
178+
exit(EXIT_FAILURE);
179+
}
171180
}
172181

173182
if (send_listen) {
174183
sprintf(buf, "L\r");
175-
write(fd, buf, strlen(buf));
184+
if (write(fd, buf, strlen(buf)) <= 0) {
185+
perror("write");
186+
exit(EXIT_FAILURE);
187+
}
176188
} else if (send_open) {
177189
sprintf(buf, "O\r");
178-
write(fd, buf, strlen(buf));
190+
if (write(fd, buf, strlen(buf)) <= 0) {
191+
perror("write");
192+
exit(EXIT_FAILURE);
193+
}
179194
}
180195

181196
/* set slcan line discipline on given tty */
@@ -229,7 +244,10 @@ int main(int argc, char **argv)
229244

230245
if (send_close) {
231246
sprintf(buf, "C\r");
232-
write(fd, buf, strlen(buf));
247+
if (write(fd, buf, strlen(buf)) <= 0) {
248+
perror("write");
249+
exit(EXIT_FAILURE);
250+
}
233251
}
234252
}
235253

slcand.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,25 +326,40 @@ int main(int argc, char *argv[])
326326

327327
if (speed) {
328328
sprintf(buf, "C\rS%s\r", speed);
329-
write(fd, buf, strlen(buf));
329+
if (write(fd, buf, strlen(buf)) <= 0) {
330+
perror("write");
331+
exit(EXIT_FAILURE);
332+
}
330333
}
331334

332335
if (btr) {
333336
sprintf(buf, "C\rs%s\r", btr);
334-
write(fd, buf, strlen(buf));
337+
if (write(fd, buf, strlen(buf)) <= 0) {
338+
perror("write");
339+
exit(EXIT_FAILURE);
340+
}
335341
}
336342

337343
if (send_read_status_flags) {
338344
sprintf(buf, "F\r");
339-
write(fd, buf, strlen(buf));
345+
if (write(fd, buf, strlen(buf)) <= 0) {
346+
perror("write");
347+
exit(EXIT_FAILURE);
348+
}
340349
}
341350

342351
if (send_listen) {
343352
sprintf(buf, "L\r");
344-
write(fd, buf, strlen(buf));
353+
if (write(fd, buf, strlen(buf)) <= 0) {
354+
perror("write");
355+
exit(EXIT_FAILURE);
356+
}
345357
} else if (send_open) {
346358
sprintf(buf, "O\r");
347-
write(fd, buf, strlen(buf));
359+
if (write(fd, buf, strlen(buf)) <= 0) {
360+
perror("write");
361+
exit(EXIT_FAILURE);
362+
}
348363
}
349364

350365
/* set slcan like discipline on given tty */
@@ -412,7 +427,10 @@ int main(int argc, char *argv[])
412427

413428
if (send_close) {
414429
sprintf(buf, "C\r");
415-
write(fd, buf, strlen(buf));
430+
if (write(fd, buf, strlen(buf)) <= 0) {
431+
perror("write");
432+
exit(EXIT_FAILURE);
433+
}
416434
}
417435

418436
/* Reset old rates */

0 commit comments

Comments
 (0)