Raspivid: fix uninitialised variable issue
authorDave Stevenson <dave.stevenson@raspberrypi.org>
Mon, 27 Feb 2017 17:38:14 +0000 (17:38 +0000)
committerpopcornmix <popcornmix@gmail.com>
Wed, 5 Apr 2017 13:30:10 +0000 (14:30 +0100)
If going through the "if (pState->netListen)" path,
sfd could potentially uninitialised before it is
used in fdopen.
Initialise to -1 and check it is >= 0 before use.

host_applications/linux/apps/raspicam/RaspiVid.c

index 8fd207b64f305698dfddb9bb2e73c70e8f9bdf99..c07d3dea8d5f4c03076e876c5e4bc25b06ee0ff0 100755 (executable)
@@ -1055,7 +1055,7 @@ static FILE *open_filename(RASPIVID_STATE *pState, char *filename)
    if (filename)
    {
       bool bNetwork = false;
-      int sfd, socktype;
+      int sfd = -1, socktype;
 
       if(!strncmp("tcp://", filename, 6))
       {
@@ -1165,7 +1165,8 @@ static FILE *open_filename(RASPIVID_STATE *pState, char *filename)
                fprintf(stderr, "Error creating socket: %s\n", strerror(errno));
          }
 
-         new_handle = fdopen(sfd, "w");
+         if (sfd >= 0)
+            new_handle = fdopen(sfd, "w");
       }
       else
       {