rimage: fix function returns address of local variable bug

path may return out the function from rimage->key_name.
Switch the usage for local variable to avoid this bug.

Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
This commit is contained in:
Pan Xiuli 2018-06-29 15:47:38 +08:00 committed by Daniel Leung
parent 81eba29a2f
commit c91c6f98c6
1 changed files with 6 additions and 6 deletions

View File

@ -90,16 +90,16 @@ int pkcs_sign(struct image *image, struct fw_image_manifest *man,
return -ENOMEM; return -ENOMEM;
/* load in RSA private key from PEM file */ /* load in RSA private key from PEM file */
if (image->key_name == NULL) { if (!image->key_name)
sprintf(path, "%s/otc_private_key.pem", PEM_KEY_PREFIX); sprintf(path, "%s/otc_private_key.pem", PEM_KEY_PREFIX);
image->key_name = path; else
} strcpy(path, image->key_name);
fprintf(stdout, " pkcs: signing with key %s\n", image->key_name); fprintf(stdout, " pkcs: signing with key %s\n", path);
fp = fopen(image->key_name, "r"); fp = fopen(path, "r");
if (fp == NULL) { if (fp == NULL) {
fprintf(stderr, "error: can't open file %s %d\n", fprintf(stderr, "error: can't open file %s %d\n",
image->key_name, -errno); path, -errno);
return -errno; return -errno;
} }
PEM_read_PrivateKey(fp, &privkey, NULL, NULL); PEM_read_PrivateKey(fp, &privkey, NULL, NULL);