Hi all,

I'll present all my patches for init.c, which patching several bugs from Coverity - you can dismiss my yesterday message. All patches was created on previous, patched file.

First:
In function get_record() I added return code testing for fprintf(), if function return value less then zero, then print out on stderr, set oops_error end return NULL.

I think, here no more actions is needed.

Patch too long - in attachment.

--
Michal Kulling

--- init.c-orig	2014-02-10 20:41:50.922024360 +0100
+++ init.c	2014-02-10 20:40:09.786021955 +0100
@@ -372,34 +372,74 @@
 			case C_REC:
 				break;
 			case D_RUNLEVEL:
-				fscanf(f, "%c\n", &runlevel);
-				break;
+				if(fscanf(f, "%c\n", &runlevel) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_THISLEVEL:
-				fscanf(f, "%c\n", &thislevel);
-				break;
+				if(fscanf(f, "%c\n", &thislevel) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+			}
+			break;
 			case D_PREVLEVEL:
-				fscanf(f, "%c\n", &prevlevel);
-				break;
+				if(fscanf(f, "%c\n", &prevlevel) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_GOTSIGN:
-				fscanf(f, "%u\n", &got_signals);
-				break;
+				if(fscanf(f, "%u\n", &got_signals) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_WROTE_WTMP_REBOOT:
-				fscanf(f, "%d\n", &wrote_wtmp_reboot);
-				break;
+				if(fscanf(f, "%d\n", &wrote_wtmp_reboot) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_WROTE_UTMP_REBOOT:
-				fscanf(f, "%d\n", &wrote_utmp_reboot);
-				break;
+				if(fscanf(f, "%d\n", &wrote_utmp_reboot) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_SLTIME:
-				fscanf(f, "%d\n", &sltime);
-				break;
+				if(fscanf(f, "%d\n", &sltime) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_DIDBOOT:
-				fscanf(f, "%d\n", &did_boot);
-				break;
+				if(fscanf(f, "%d\n", &did_boot) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_WROTE_WTMP_RLEVEL:
-				fscanf(f, "%d\n", &wrote_wtmp_rlevel);
-				break;
+				if(fscanf(f, "%d\n", &wrote_wtmp_rlevel) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
+			break;
 			case D_WROTE_UTMP_RLEVEL:
-				fscanf(f, "%d\n", &wrote_utmp_rlevel);
+				if(fscanf(f, "%d\n", &wrote_utmp_rlevel) < 0){
+					fprintf(stderr, "Read state pipe: %s\n", strerror(errno));
+					oops_error = -1;
+					return NULL;
+				}
 				break;
 			default:
 				if (cmd > 0 || cmd == C_EOF) {
@@ -418,10 +458,17 @@
 			get_void(f);
 			break;
 		case C_PID:
-			fscanf(f, "%d\n", &(p->pid));
+			if(fscanf(f, "%d\n", &(p->pid)) < 0){
+				fprintf(stderr, "Failed to read PID: %s\n", strerror(errno));
+				return NULL;
+			}
 			break;
 		case C_EXS:
-			fscanf(f, "%u\n", &(p->exstat));
+			if(fscanf(f, "%u\n", &(p->exstat)) < 0){
+				fprintf(stderr, "Failed to read EXS: %s\n", strerror(errno));
+				oops_error = -1;
+				return NULL;
+			}
 			break;
 		case C_LEV:
 			get_string(p->rlevel, sizeof(p->rlevel), f);

Reply via email to