Browse code

scan_options - fixing up segfault caused by zeroed out scan_options struct when using sigtool to test signatures

Mickey Sola authored on 2018/09/25 04:35:41
Showing 1 changed files
... ...
@@ -171,12 +171,9 @@ static int hashpe(const char *filename, unsigned int class, int type)
171 171
     const char *fmptr;
172 172
     struct cl_engine *engine;
173 173
     cli_ctx ctx;
174
-	struct cl_scan_options options;
174
+    struct cl_scan_options options;
175 175
     int fd, ret;
176 176
 
177
-	memset(&options, 0, sizeof(struct cl_scan_options));
178
-	ctx.options = &options;
179
-
180 177
     /* build engine */
181 178
     if(!(engine = cl_engine_new())) {
182 179
 	mprintf("!hashpe: Can't create new engine\n");
... ...
@@ -204,7 +201,9 @@ static int hashpe(const char *filename, unsigned int class, int type)
204 204
 
205 205
     /* prepare context */
206 206
     memset(&ctx, '\0', sizeof(cli_ctx));
207
+    memset(&options, 0, sizeof(struct cl_scan_options));
207 208
     ctx.engine = engine;
209
+    ctx.options = &options;
208 210
     ctx.options->parse = ~0;
209 211
     ctx.containers = cli_calloc(sizeof(cli_ctx_container), engine->maxreclevel + 2);
210 212
     if(!ctx.containers) {
... ...
@@ -2214,8 +2213,6 @@ static void matchsig(const char *sig, const char *offset, int fd)
2214 2214
 	struct cl_scan_options options;
2215 2215
 	int ret;
2216 2216
 
2217
-	memset(&options, 0, sizeof(struct cl_scan_options));
2218
-	ctx.options = &options;
2219 2217
 
2220 2218
     mprintf("SUBSIG: %s\n", sig);
2221 2219
 
... ...
@@ -2243,7 +2240,9 @@ static void matchsig(const char *sig, const char *offset, int fd)
2243 2243
 	return;
2244 2244
     }
2245 2245
     memset(&ctx, '\0', sizeof(cli_ctx));
2246
+    memset(&options, 0, sizeof(struct cl_scan_options));
2246 2247
     ctx.engine = engine;
2248
+    ctx.options = &options;
2247 2249
     ctx.options->parse = ~0;
2248 2250
     ctx.containers = cli_calloc(sizeof(cli_ctx_container), engine->maxreclevel + 2);
2249 2251
     if(!ctx.containers) {
... ...
@@ -3396,12 +3395,9 @@ static int dumpcerts(const struct optstruct *opts)
3396 3396
     const char * fmptr;
3397 3397
     struct cl_engine *engine;
3398 3398
     cli_ctx ctx;
3399
-	struct cl_scan_options options;
3399
+    struct cl_scan_options options;
3400 3400
     int fd, ret;
3401 3401
     uint8_t shash1[SHA1_HASH_SIZE];
3402
-
3403
-	memset(&options, 0, sizeof(struct cl_scan_options));
3404
-	ctx.options = &options;
3405 3402
 	
3406 3403
     logg_file = NULL;
3407 3404
 
... ...
@@ -3441,7 +3437,9 @@ static int dumpcerts(const struct optstruct *opts)
3441 3441
 
3442 3442
     /* prepare context */
3443 3443
     memset(&ctx, '\0', sizeof(cli_ctx));
3444
+    memset(&options, 0, sizeof(struct cl_scan_options));
3444 3445
     ctx.engine = engine;
3446
+    ctx.options = &options;
3445 3447
     ctx.options->parse = ~0;
3446 3448
     ctx.containers = cli_calloc(sizeof(cli_ctx_container), engine->maxreclevel + 2);
3447 3449
     if(!ctx.containers) {