This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 256919 - fix issues discovered in rfs_controller and rfs_preload
Summary: fix issues discovered in rfs_controller and rfs_preload
Status: VERIFIED FIXED
Alias: None
Product: cnd
Classification: Unclassified
Component: Remote (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Vladimir Kvashin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-02 10:51 UTC by Vladimir Kvashin
Modified: 2016-01-29 14:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
zipped static analysis result in hml form (10.66 KB, application/octet-stream)
2015-12-02 16:30 UTC, Vladimir Kvashin
Details
possible fix (9.05 KB, patch)
2016-01-01 09:48 UTC, Vladimir Kvashin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Kvashin 2015-12-02 10:51:35 UTC
Below is discover report. This should be fixed as if build is really really long leak can become significant

***************** Discover Memory Report *****************

25 allocations at 1 location left on the heap with a total size of 500 bytes

    LEAK 1: 25 allocations with total size of 500 bytes
	main() + 0xa26  <rfs_controller.c:789>
		786:    
		787:        while (1) {
		788:            /* wait for a client to talk to us */
		789:=>          connection_data* conn_data = (connection_data*) malloc(sizeof (connection_data));
		790:            socklen_t addrlen = sizeof (conn_data->pin);
		791:            if ((conn_data->sd = accept(sd, (struct sockaddr *) & conn_data->pin, &addrlen)) == -1) {
		792:                perror("accept");
	0x403453 

DISCOVER SUMMARY:
	unique errors   : 0 (0 total)
	unique warnings : 0 (0 total)
Comment 1 Vladimir Kvashin 2015-12-02 11:17:42 UTC
There are also several issues wit rfs_preload:

    LEAK 18: 1 allocation with total size of 1025 bytes
	rfs_startup() + 0x12d  <rfs_preload.c:361>
		358:            getcwd(p, PATH_MAX + 1);
		359:            dir = p;
		360:        }
		361:=>      char* real_dir = malloc(PATH_MAX + 1);
		362:        if ( realpath(dir, real_dir)) {
		363:            char *to_free = dir;
		364:            dir = real_dir;
	_init() + 0x35 
	call_init() + 0x119 
	is_dep_init() + 0xa2 
	elf_bndr() + 0x438 
	_elf_rtbndr() + 0x13 
	0xfe230587 : UNKNOWN
	ucrypto_init() + 0x26 



    LEAK 65: 1 allocation with total size of 63 bytes
	rfs_startup() + 0x1fb  <rfs_preload.c:374>
		371:            dir = strdup(dir);
		372:        } else {
		373:            my_dir_len++;
		374:=>          void *p = malloc(my_dir_len + 1);
		375:            strcpy(p, dir);
		376:            strcat(p, "/");
		377:            dir = p;
	_init() + 0x24 
	call_init() + 0x119 
	is_dep_init() + 0xa2 
	elf_bndr() + 0x438 
	_elf_rtbndr() + 0x13 
	0xfe230587 : UNKNOWN
	ucrypto_init() + 0x26 


ERROR 1 (UAW): writing to unallocated memory at address 0x81f7c40 (63 bytes) on the heap at:
	strdup() + 0x48 
	rfs_startup() + 0xe5  <rfs_preload.c:355>
		352:        //getcwd(curr_dir, curr_dir_len);
		353:        char* dir = getenv("RFS_CONTROLLER_DIR");
		354:        if (dir) {
		355:=>          dir = strdup(dir);
		356:        } else {
		357:            char* p = malloc(PATH_MAX + 1);
		358:            getcwd(p, PATH_MAX + 1);
	_init() + 0x24 
	call_init() + 0x119 
	is_dep_init() + 0xa2 
	elf_bndr() + 0x438 
	_elf_rtbndr() + 0x13 
	0x7f0f028f : UNKNOWN

ERROR 2 (UAR): reading from unallocated memory "*real_dir" at address 0x8208d70 (62 bytes) on the heap at:
	rfs_startup() + 0x211  <rfs_preload.c:375>
		372:        } else {
		373:            my_dir_len++;
		374:            void *p = malloc(my_dir_len + 1);
		375:=>          strcpy(p, dir);
		376:            strcat(p, "/");
		377:            dir = p;
		378:        }
	_init() + 0x24 
	call_init() + 0x119 
	is_dep_init() + 0xa2 
	elf_bndr() + 0x438 
	_elf_rtbndr() + 0x13 
	0x7f0f028f : UNKNOWN
	ucrypto_init() + 0x26
Comment 2 Vladimir Kvashin 2015-12-02 15:10:03 UTC
There are also issues discovered with static analysis.

The summary is:
PREVISE SUMMARY for ../release/bin/SunOS-x86/rfs_preload.so: 
0 error(s), 4 warning(s), 0 leak(s) in total
PREVISE SUMMARY for ../release/bin/SunOS-x86/rfs_controller: 
0 error(s), 5 warning(s), 2 leak(s) in total

Details are:

========== rfs_preload.so static analysis ==========

STATIC report of ../release/bin/SunOS-x86/rfs_preload.so:
WARNING 1 (MRC): missing null-pointer check after malloc: malloc(1025):
	rfs_startup()  <rfs_preload.c : 357>
		354:	    if (dir) {
		355:	        dir = strdup(dir);
		356:	    } else {
		357:=>	        char* p = malloc(PATH_MAX + 1);
		358:	        getcwd(p, PATH_MAX + 1);
WARNING 2 (MRC): missing null-pointer check after malloc: malloc(1025):
	rfs_startup()  <rfs_preload.c : 361>
		358:	        getcwd(p, PATH_MAX + 1);
		359:	        dir = p;
		360:	    }
		361:=>	    char* real_dir = malloc(PATH_MAX + 1);
		362:	    if ( realpath(dir, real_dir)) {
WARNING 3 (MRC): missing null-pointer check after malloc: malloc(((unsigned).XA$BAAB3lwXWUgk.my_dir_len+1)):
	rfs_startup()  <rfs_preload.c : 374>
		371:	        dir = strdup(dir);
		372:	    } else {
		373:	        my_dir_len++;
		374:=>	        void *p = malloc(my_dir_len + 1);
		375:	        strcpy(p, dir);
WARNING 4 (MRC): missing null-pointer check after malloc: malloc(8):
	pthread_create()  <rfs_preload.c : 425>
		422:	    if (!prev) {
		423:	        prev = (int (*)(void*, void*, void * (*)(void *), void*)) get_real_addr(pthread_create);
		424:	    }
		425:=>	    pthread_routine_data *data = malloc(sizeof (pthread_routine_data));
		426:	    // TODO: check for null???
PREVISE SUMMARY for ../release/bin/SunOS-x86/rfs_preload.so: 0 error(s), 4 warning(s), 0 leak(s) in total


========== rfs_controller static analysis ==========

STATIC report of ../release/bin/SunOS-x86/rfs_controller:
LEAK 1 : 1 block left allocated on heap with a total size of ? bytes
	init_files()  <rfs_controller.c : 590>
		587:	        } else if (state == DIRECTORY) { // directory
		588:	            create_dir(path);
		589:	        } else if (state == LINK) { // symbolic link
		590:=>	            char lnk_src[bufsize]; // it is followed by a line that contains the link source
		591:	            if( !fgets(lnk_src, sizeof lnk_src, stdin)) {
LEAK 2 : 1 block left allocated on heap with a total size of 20 bytes
	main()  <rfs_controller.c : 783>
		779:	    pthread_detach(ping_pong_thread);
		781:	    while (1) {
		782:	        /* wait for a client to talk to us */
		783:=>	        connection_data* conn_data = (connection_data*) malloc(sizeof (connection_data));
		784:	        socklen_t addrlen = sizeof (conn_data->pin);
WARNING 1 (MRC): missing null-pointer check after malloc: malloc(((unsigned)((int)((unsigned)namelen)+((unsigned)((int)strlen(real_path)))+14))):
	add_file_to_list()  <rfs_controller.c : 411>
		408:	    int namelen = strlen(filename);
		409:	    int realpath_len = strlen(real_path);
		410:	    int size = sizeof(file_elem) + namelen + realpath_len + 2;
		411:=>	    file_elem *fe = (file_elem*) malloc(size);
		412:	    fe->next = NULL;
WARNING 2 (MRC): missing null-pointer check after malloc: malloc(20):
	main()  <rfs_controller.c : 783>
		779:	    pthread_detach(ping_pong_thread);
		781:	    while (1) {
		782:	        /* wait for a client to talk to us */
		783:=>	        connection_data* conn_data = (connection_data*) malloc(sizeof (connection_data));
		784:	        socklen_t addrlen = sizeof (conn_data->pin);
WARNING 3 (MRC): missing null-pointer check after malloc: malloc(((unsigned).XA$BAAB3lwXWksk.data_cnt*4)):
	stop_adding_file_data()  <rfs_filedata.c : 115>
		111:	}
		113:	void stop_adding_file_data() {
		114:	    int el_size = sizeof(struct file_data *);
		115:=>	    data = malloc(data_cnt * el_size);
		116:	    int next = 0;
WARNING 4 (MRC): missing null-pointer check after malloc: malloc(8):
	add_file_data()  <rfs_filedata.c : 134>
		131:	        return NULL;
		132:	    }
		133:	    data_cnt++;
		134:=>	    struct adding_file_data_node *node = malloc(sizeof(struct adding_file_data_node));
		136:	    node->fd = (file_data*) malloc(sizeof(file_data) + strlen(filename) + 1);
WARNING 5 (MRC): missing null-pointer check after malloc: malloc(strlen(filename)+29):
	add_file_data()  <rfs_filedata.c : 136>
		132:	    }
		133:	    data_cnt++;
		134:	    struct adding_file_data_node *node = malloc(sizeof(struct adding_file_data_node));
		136:=>	    node->fd = (file_data*) malloc(sizeof(file_data) + strlen(filename) + 1);
		137:	    pthread_mutex_init(&node->fd->mutex, NULL);
PREVISE SUMMARY for ../release/bin/SunOS-x86/rfs_controller: 0 error(s), 5 warning(s), 2 leak(s) in total


It would be fine to fix these either.
Comment 3 Vladimir Kvashin 2015-12-02 16:30:52 UTC
Created attachment 157620 [details]
zipped static analysis result in hml form
Comment 4 Vladimir Kvashin 2015-12-28 07:42:19 UTC
fixes on enum/release81
  a39b365a5333, 7f1a074777b1, 45dc1b064b3d, 80e0db5ee60f
Comment 5 Vladimir Kvashin 2016-01-01 09:48:06 UTC
Created attachment 157964 [details]
possible fix
Comment 6 Quality Engineering 2016-01-12 02:28:18 UTC
Integrated into 'main-silver', will be available in build *201601120002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b5913a69d850
User: Vladimir Kvashin <vkvashin@netbeans.org>
Log: fixed project metadata (#256919 - fix issues discovered in rfs_controller and rfs_preload)
(transplanted from ad32ee2dbcdf14e88cb90ea0d2db9b715d6d3a76)
Comment 7 Vladimir Kvashin 2016-01-13 10:54:21 UTC
more fixes on enum:
3d6099405a38
3c47d98db1ba
Comment 8 Alexander Simon 2016-01-14 08:52:02 UTC
Please redo fix 305478:92c8dea4f01b.
It introduces possible NPE in the method RfsLocalController.checkVersion()
Comment 9 Vladimir Kvashin 2016-01-14 09:38:24 UTC
(In reply to Alexander Simon from comment #8)
Thanks. Fixed:
53dfe1d02582
Comment 10 Vladimir Kvashin 2016-01-14 19:48:16 UTC
More fixes on enum:
b0e098d0de62
b3676044604d
37b94762a6a8
Comment 11 Quality Engineering 2016-01-18 03:04:16 UTC
Integrated into 'main-silver', will be available in build *201601180002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/36a1dbbec847
User: Vladimir Kvashin <vkvashin@netbeans.org>
Log: fixing #256919 - fix issues discovered in rfs_controller and rfs_preload
(transplanted from 92c8dea4f01b35e4d2ada6ed27472bd86075d684)