diff options
author | Sebastian Rasmussen <sebras@hotmail.com> | 2008-03-21 18:46:13 +0100 |
---|---|---|
committer | Sebastian Rasmussen <sebras@hotmail.com> | 2008-03-21 18:46:13 +0100 |
commit | f14424f844b9b14f4716925467c06f951c6df920 (patch) | |
tree | bf51c5fe7d88ce9a37f52b99743641148ddd7090 | |
parent | 9575a595c007315686b58babbe99f4ff949971f4 (diff) | |
download | mupdf-f14424f844b9b14f4716925467c06f951c6df920.tar.xz |
Added proper error handling when setting passwords.
-rw-r--r-- | apps/pdftool.c | 6 | ||||
-rw-r--r-- | include/mupdf/syntax.h | 6 | ||||
-rw-r--r-- | mupdf/pdf_crypt.c | 27 |
3 files changed, 24 insertions, 15 deletions
diff --git a/apps/pdftool.c b/apps/pdftool.c index 3daeb777..559eca03 100644 --- a/apps/pdftool.c +++ b/apps/pdftool.c @@ -83,9 +83,9 @@ void opensrc(char *filename, char *password, int loadpages) if (src->crypt) { - int okay = pdf_setpassword(src->crypt, password); - if (!okay) - die(fz_throw("invalid password")); + error = pdf_setpassword(src->crypt, password); + if (error) + die(fz_rethrow(error, "invalid password")); } if (loadpages) diff --git a/include/mupdf/syntax.h b/include/mupdf/syntax.h index f9602c35..04feb57b 100644 --- a/include/mupdf/syntax.h +++ b/include/mupdf/syntax.h @@ -55,9 +55,9 @@ struct pdf_crypt_s fz_error *pdf_newdecrypt(pdf_crypt **cp, fz_obj *enc, fz_obj *id); fz_error *pdf_newencrypt(pdf_crypt **cp, char *userpw, char *ownerpw, int p, int n, fz_obj *id); -int pdf_setpassword(pdf_crypt *crypt, char *pw); -int pdf_setuserpassword(pdf_crypt *crypt, char *pw, int pwlen); -int pdf_setownerpassword(pdf_crypt *crypt, char *pw, int pwlen); +fz_error *pdf_setpassword(pdf_crypt *crypt, char *pw); +fz_error *pdf_setuserpassword(pdf_crypt *crypt, char *pw, int pwlen); +fz_error *pdf_setownerpassword(pdf_crypt *crypt, char *pw, int pwlen); fz_error *pdf_cryptstream(fz_filter **fp, pdf_crypt *crypt, int oid, int gid); void pdf_cryptobj(pdf_crypt *crypt, fz_obj *obj, int oid, int gid); diff --git a/mupdf/pdf_crypt.c b/mupdf/pdf_crypt.c index 2fac478f..d827e0c6 100644 --- a/mupdf/pdf_crypt.c +++ b/mupdf/pdf_crypt.c @@ -328,16 +328,24 @@ pdf_newencrypt(pdf_crypt **cp, char *userpw, char *ownerpw, int p, int n, fz_obj * Return true if the password is valid. */ -int +fz_error * pdf_setpassword(pdf_crypt *crypt, char *pw) { - int okay = pdf_setuserpassword(crypt, pw, strlen(pw)); - if (!okay) - okay = pdf_setownerpassword(crypt, pw, strlen(pw)); - return okay; + fz_error *error; + + error = pdf_setuserpassword(crypt, pw, strlen(pw)); + if (error) + { + fz_droperror(error); + error = pdf_setownerpassword(crypt, pw, strlen(pw)); + if (error) + return fz_rethrow(error, "Invalid password"); + } + + return fz_okay; } -int +fz_error * pdf_setuserpassword(pdf_crypt *crypt, char *userpw, int pwlen) { unsigned char saved[32]; @@ -349,11 +357,12 @@ pdf_setuserpassword(pdf_crypt *crypt, char *userpw, int pwlen) memcpy(crypt->u, saved, 32); if (memcmp(test, saved, crypt->r == 3 ? 16 : 32) != 0) - return 0; - return 1; + return fz_throw("Invalid password"); + + return fz_okay; } -int +fz_error * pdf_setownerpassword(pdf_crypt *crypt, char *ownerpw, int pwlen) { unsigned char buf[32]; |