comparison svr-authpubkey.c @ 1883:f54451afc046

use buf_getptr and m_free on every iteration before m_malloc to insure no memory leaks are happening
author HansH111 <hans@atbas.org>
date Tue, 15 Mar 2022 18:57:21 +0000
parents d39cfedaf015
children 5d8dbb6fdab7
comparison
equal deleted inserted replaced
1882:2839daa507b3 1883:f54451afc046
354 354
355 TRACE(("checkpubkey_line: line pos = %d len = %d", line->pos, line->len)) 355 TRACE(("checkpubkey_line: line pos = %d len = %d", line->pos, line->len))
356 356
357 ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL); 357 ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL);
358 358
359 /* free pubkey_info if it is filled */
360 if (ses.authstate.pubkey_info) {
361 m_free(ses.authstate.pubkey_info);
362 ses.authstate.pubkey_info = NULL;
363 }
359 if (ret == DROPBEAR_SUCCESS) { 364 if (ret == DROPBEAR_SUCCESS) {
360 if (options_buf) { 365 if (options_buf) {
361 ret = svr_add_pubkey_options(options_buf, line_num, filename); 366 ret = svr_add_pubkey_options(options_buf, line_num, filename);
362 } 367 }
363 /* save the (optional) public key information */ 368 /* save the (optional) public key information */
364 if (infolen) { 369 if (infolen) {
365 ses.authstate.pubkey_info = m_malloc(infolen + 1); 370 ses.authstate.pubkey_info = m_malloc(infolen + 1);
366 if (ses.authstate.pubkey_info) { 371 if (ses.authstate.pubkey_info) {
367 strncpy(ses.authstate.pubkey_info, &line->data[infopos], infolen); 372 strncpy(ses.authstate.pubkey_info,(const char *) buf_getptr(line, infopos), infolen);
368 ses.authstate.pubkey_info[infolen]='\0'; 373 ses.authstate.pubkey_info[infolen]='\0';
369 } 374 }
370 } else {
371 ses.authstate.pubkey_info = NULL;
372 } 375 }
373 } 376 }
374 377
375 out: 378 out:
376 if (options_buf) { 379 if (options_buf) {