Skip to contentSkip to conversation

coverity fix in alsa-libs

PATCH Renu Tyagi 3 participants 4 messages Sep 15, 2014

lore
Share & tools
lore

Renu Tyagi

author
#0 lore raw

Hi,

I ran Coverity analysis tool on alsa and found some bugs. Bug and Patch description

1. Changed file : aserver.c
Socket not closed before returning when bind fails Community Code:

if (bind(sock, (struct sockaddr *) addr, size) < 0) { int result = -errno;
SYSERROR("bind failed");
return result;
}
return sock;
}

Recommended Code :

if (bind(sock, (struct sockaddr *) addr, size) < 0) {
	int result = -errno;
	SYSERROR("bind failed");                                                
	close(sock);                                                
	return result;                                                                                              
}

return sock;
}

2.Changed file : control_shm.c
Socket not closed before returning when connect fails

Community Code:
if (connect(sock, (struct sockaddr *) addr, size) < 0)

    return -errno;
	return sock;
}

Recommended Code :

if (connect(sock, (struct sockaddr *) addr, size) < 0){
    SYSERR("connect failed");
    close(sock);
    return -errno;
	}

return sock;
}

3.Changed file : pcm_shm.c
Socket not closed before returning when connect fails

Community Code:
if (connect(sock, (struct sockaddr *) addr, size) < 0) {

   SYSERR("connect failed");                                           
	return -errno;

}
return sock;
}
Recommended Code :
if (connect(sock, (struct sockaddr *) addr, size) < 0) {
SYSERR("connect failed");
close(sock);
return -errno;
}
return sock;
}

PFA patch.

Thanks & Regards,

Renu Tyagi

aserver/aserver.c +1 -0
index 73ea4e9..ca9aaf3 100644
@@ -75,6 +75,7 @@ static int make_local_socket(const char *filename)
 	if (bind(sock, (struct sockaddr *) addr, size) < 0) {
 		int result = -errno;
 		SYSERROR("bind failed");
+		close(sock);
 		return result;
 	}
 
src/control/control_shm.c +4 -1
index abab398..4083ec5 100644
@@ -436,8 +436,11 @@ static int make_local_socket(const char *filename)
 	addr->sun_family = AF_LOCAL;
 	memcpy(addr->sun_path, filename, l);
 
-	if (connect(sock, (struct sockaddr *) addr, size) < 0)
+	if (connect(sock, (struct sockaddr *) addr, size) < 0){
+		SYSERR("connect failed");
+		close(sock);
 		return -errno;
+	}
 	return sock;
 }
 
src/pcm/pcm_shm.c +1 -0
index 69d0524..3fbecca 100644
@@ -649,6 +649,7 @@ static int make_local_socket(const char *filename)
 
 	if (connect(sock, (struct sockaddr *) addr, size) < 0) {
 		SYSERR("connect failed");
+		close(sock);
 		return -errno;
 	}
 	return sock;
#1 lore raw
Quoted 3 lines · Renu Tyagi

Hi,

I ran Coverity analysis tool on alsa and found some bugs.

May I suggest that we remove aserver and the shm plugin instead of applying the patch? Three days ago I tried to use it for testing my fix to the share plugin, but failed. In other words: if even speaker-test cannot be made to work on it without crashing and/or hanging or valgrind errors, then I'd rather be aggressive here.

And next time please CC: Takashi Iwai on all alsa-lib patches :)

Quoted 79 lines

Bug and Patch description

1. Changed file : aserver.c
Socket not closed before returning when bind fails Community Code:

if (bind(sock, (struct sockaddr *) addr, size) < 0) { int result = -errno;
SYSERROR("bind failed");
return result;
}
return sock;
}

Recommended Code :

if (bind(sock, (struct sockaddr *) addr, size) < 0) {
	int result = -errno;
	SYSERROR("bind failed");
	close(sock);
	return result;
}

return sock;
}

2.Changed file : control_shm.c
Socket not closed before returning when connect fails

Community Code:
if (connect(sock, (struct sockaddr *) addr, size) < 0)

     return -errno;
	return sock;
}

Recommended Code :

if (connect(sock, (struct sockaddr *) addr, size) < 0){
     SYSERR("connect failed");
     close(sock);
     return -errno;
	}

return sock;
}

3.Changed file : pcm_shm.c
Socket not closed before returning when connect fails

Community Code:

if (connect(sock, (struct sockaddr *) addr, size) < 0) {
    SYSERR("connect failed");
	return -errno;
    }

return sock;
}
Recommended Code :
if (connect(sock, (struct sockaddr *) addr, size) < 0) {
SYSERR("connect failed");
close(sock);
return -errno;
}
return sock;
}

PFA patch.

Thanks & Regards,

Renu Tyagi

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Signature · 1 line
Alexander E. Patrakov
#2 lore raw

At Mon, 15 Sep 2014 17:36:02 +0600,

Quoted 6 lines · Alexander E. Patrakov
Quoted 3 lines · Renu Tyagi

Hi,

I ran Coverity analysis tool on alsa and found some bugs.

Quoted 7 lines

May I suggest that we remove aserver and the shm plugin instead of applying the patch? Three days ago I tried to use it for testing my fix to the share plugin, but failed. In other words: if even speaker-test cannot be made to work on it without crashing and/or hanging or valgrind errors, then I'd rather be aggressive here.

And next time please CC: Takashi Iwai on all alsa-lib patches :)

I'm for removing aserver & co, too, but let's put it as post-1.0.29 item, since Jaroslav seems preparing 1.0.29 release now.

thanks,

Takashi

Quoted 85 lines
Quoted 80 lines

Bug and Patch description

1. Changed file : aserver.c
Socket not closed before returning when bind fails Community Code:

if (bind(sock, (struct sockaddr *) addr, size) < 0) { int result = -errno;
SYSERROR("bind failed");
return result;
}
return sock;
}

Recommended Code :

if (bind(sock, (struct sockaddr *) addr, size) < 0) {
	int result = -errno;
	SYSERROR("bind failed");
	close(sock);
	return result;
}

return sock;
}

2.Changed file : control_shm.c
Socket not closed before returning when connect fails

Community Code:
if (connect(sock, (struct sockaddr *) addr, size) < 0)

     return -errno;
	return sock;
}

Recommended Code :

if (connect(sock, (struct sockaddr *) addr, size) < 0){
     SYSERR("connect failed");
     close(sock);
     return -errno;
	}

return sock;
}

3.Changed file : pcm_shm.c
Socket not closed before returning when connect fails

Community Code:

if (connect(sock, (struct sockaddr *) addr, size) < 0) {
    SYSERR("connect failed");
	return -errno;
    }

return sock;
}
Recommended Code :
if (connect(sock, (struct sockaddr *) addr, size) < 0) {
SYSERR("connect failed");
close(sock);
return -errno;
}
return sock;
}

PFA patch.

Thanks & Regards,

Renu Tyagi

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Signature · 1 line
Alexander E. Patrakov
#3 lore raw

At Mon, 15 Sep 2014 13:48:11 +0200,

Quoted 15 lines · Takashi Iwai

At Mon, 15 Sep 2014 17:36:02 +0600,

Quoted 12 lines · Alexander E. Patrakov
Quoted 3 lines · Renu Tyagi

Hi,

I ran Coverity analysis tool on alsa and found some bugs.

May I suggest that we remove aserver and the shm plugin instead of applying the patch? Three days ago I tried to use it for testing my fix to the share plugin, but failed. In other words: if even speaker-test cannot be made to work on it without crashing and/or hanging or valgrind errors, then I'd rather be aggressive here.

Quoted 4 lines
Quoted 1 line

And next time please CC: Takashi Iwai on all alsa-lib patches :)

I'm for removing aserver & co, too, but let's put it as post-1.0.29 item, since Jaroslav seems preparing 1.0.29 release now.

BTW, I haven't received the original mail from ML server. (The delivery seems slowed down by some reason, so it might be that,
though...)

Takashi