<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.5pt;
        font-family:Consolas;
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:Consolas;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoPlainText"><span style="font-family:"Courier New"">openggsn: Check return codes and take error paths on failure.<br>
<br>
Return early when socket() returns -1, and check return codes where indicated by some TODOs.  This removes 2 TODOs and fixes a compiler warning about assignment to a variable which then isn't used.<br>
<br>
Signed-off-by: Michael McTernan <mike.mcternan@wavemobile.com><br>
Index: osmobss/openggsn/lib/tun.c<br>
===================================================================<br>
--- osmobss.orig/openggsn/lib/tun.c   2015-04-28 10:51:37.960449539 +0100<br>
+++ osmobss/openggsn/lib/tun.c   2015-04-28 10:54:40.301130739 +0100<br>
@@ -117,6 +117,7 @@ int tun_sifflags(struct tun_t *this, int<br>
     ifr.ifr_name[IFNAMSIZ - 1] = 0;  /* Make sure to terminate */<br>
     if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {<br>
           SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");<br>
+          return -1;<br>
     }<br>
     if (ioctl(fd, SIOCSIFFLAGS, &ifr)) {<br>
           SYS_ERR(DTUN, LOGL_ERROR, errno,<br>
@@ -318,9 +319,19 @@ int tun_addaddr(struct tun_t *this,<br>
     req.n.nlmsg_seq = 0;<br>
     req.n.nlmsg_flags |= NLM_F_ACK;<br>
 <br>
-    status = sendmsg(fd, &msg, 0);   /* TODO Error check */<br>
+    status = sendmsg(fd, &msg, 0);<br>
+    if (status == -1) {<br>
+          SYS_ERR(DTUN, LOGL_ERROR, errno, "sendmsg() failed");<br>
+          close(fd);<br>
+          return -1;<br>
+    }<br>
+<br>
+    status = tun_sifflags(this, IFF_UP | IFF_RUNNING);<br>
+    if (status == -1) {<br>
+          close(fd);<br>
+          return -1;<br>
+    }<br>
 <br>
-    tun_sifflags(this, IFF_UP | IFF_RUNNING);   /* TODO */<br>
     close(fd);<br>
     this->addrs++;<br>
     return 0;<br>
<o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>