diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit fcde060fbbcbcc2f0c325a1b6fe370882153ea4d
parent a8cd189f0df149ccef77f2b8ca2cf9d7f6d73cf7
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sun, 23 Jan 2022 15:26:56 +0100

fix invalid read of priv http_header

Diffstat:
Msrc/caldav.c | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/caldav.c b/src/caldav.c @@ -102,8 +102,10 @@ char* read_tokenfile() { char* new_access_token = extract_json_value(token_buf, "access_token", true); fprintf(stderr, "New access token: %s\n", new_access_token); - strncpy(access_token, new_access_token, 200); - free(new_access_token); + if (new_access_token != NULL) { + strncpy(access_token, new_access_token, 200); + free(new_access_token); + } // program segfaults if NULL value is provided to atoi char* token_ttl_str = extract_json_value(token_buf, "expires_in", false); @@ -382,7 +384,10 @@ char* get_oauth_code(const char* verifier, WINDOW* header) { return NULL; } - return code; + char* oauth_code = malloc(strlen(code) + 1); + strcpy(oauth_code, code); + + return oauth_code; } char* caldav_req(struct tm* date, char* url, char* http_method, char* postfields, int depth) { @@ -606,6 +611,8 @@ int caldav_sync(struct tm* date, // get acess token using code and verifier get_access_token(code, challenge, false); + + free(code); } pthread_create(&progress_tid, NULL, show_progress, (void*)header); @@ -634,7 +641,7 @@ int caldav_sync(struct tm* date, wclear(header); wresize(header, LINES, getmaxx(header)); char* info_txt = "Offline, corrupted or otherwise invalid OAuth2 credential tokenfile.\n" - "Go online or delete tokenfile '%s' to retry login.\n" + "Go online or delete tokenfile '%s' and restart diary to retry.\n" "Press any key to continue."; mvwprintw(header, 0, 0, info_txt, CONFIG.google_tokenfile); wrefresh(header);