Skip to content

Commit

Permalink
Merge branch 'pr-160'
Browse files Browse the repository at this point in the history
  • Loading branch information
klali committed May 7, 2018
2 parents fa3833b + c32ddd9 commit 38e494c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ykpamcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>

#include <ykpers.h>

Expand Down Expand Up @@ -104,7 +105,10 @@ parse_args(int argc, char **argv,
*slot = 2;
break;
case 'A':
strncpy(*action, optarg, ACTION_MAX_LEN);
if (snprintf(*action, ACTION_MAX_LEN, "%s", optarg) >= ACTION_MAX_LEN) {
fprintf(stderr, "action too long: %s\n", optarg);
exit(1);
}
break;
case 'p':
*output_dir = optarg;
Expand Down Expand Up @@ -164,9 +168,14 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
*/

if (!output_dir){
char fullpath[256];
snprintf(fullpath, 256,"%s/.yubico",p->pw_dir);

char fullpath[PATH_MAX];
int i = snprintf(fullpath, PATH_MAX, "%s/.yubico", p->pw_dir);

if (i < 0 || i >= PATH_MAX) {
fprintf(stderr, "Failed to construct fullpath: %s\n", p->pw_dir);
goto out;
}

//check if directory exists
if (stat(fullpath,&st)!=0 ){
if(mkdir(fullpath, S_IRWXU)==-1){
Expand Down Expand Up @@ -283,7 +292,7 @@ main(int argc, char **argv)
ykp_errno = 0;
yk_errno = 0;

strcpy (action, ACTION_ADD_HMAC_CHALRESP);
strncpy(action, ACTION_ADD_HMAC_CHALRESP, ACTION_MAX_LEN);

if (! parse_args(argc, argv,
&slot, &verbose,
Expand Down

0 comments on commit 38e494c

Please sign in to comment.