Skip to contentSkip to conversation

Mini-OS: Small fix for NULL pointer handling

PATCH Applied Dietmar Hahn 2 participants 2 messages Jan 26, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mini-OS: Small fix for NULL pointer handling

Hi Gregor,

attached is a small patch for netfront.c.
A compiler warning is fixed when -O? is used.
If the network is not configured, backend gets NULL from xenbus_read() and this leads sometimes to a crash because this pointer is used later.
I hope this fix is OK. Please have a look and send comments! Thanks.

Dietmar.

# HG changeset patch
# User [email protected]
# Date 1169817843 -3600
# Node ID 6d4800573fd7d97c4b007d3dc9f89bf883605063 # Parent 82c306ad212e3714cf9292611a0ddb8de7a3b5dc

- Handle returned backend==NULL || mac==NULL, this leads sometimes to a crash.
- Handle initializing of np->rx.req_prod_pvt to avoid a compiler warning when using -O?.

extras/mini-os/netfront.c +12 -2
diff -r 82c306ad212e -r 6d4800573fd7 extras/mini-os/netfront.c
@@ -324,6 +324,14 @@ done:
     msg = xenbus_read(XBT_NIL, "device/vif/0/backend", &backend);
     msg = xenbus_read(XBT_NIL, "device/vif/0/mac", &mac);
 
+    if((backend == NULL) || (mac == NULL)) {
+        struct evtchn_close op = { info->local_port };
+        printk("%s: backend/mac failed\n", __func__);
+        unbind_evtchn(info->local_port);
+        HYPERVISOR_event_channel_op(EVTCHNOP_close, &op);
+        return;
+    }
+
     printk("backend at %s\n",backend);
     printk("mac is %s\n",mac);
 
@@ -383,8 +391,10 @@ void init_rx_buffers(void)
     netif_rx_request_t *req;
     int notify;
 
-    np->rx.req_prod_pvt = requeue_idx;
-
+        /* Initializing with 0 to avoid a cc warning with -O?, but
+         * initializing mmust be! */
+    //np->rx.req_prod_pvt = requeue_idx;
+    np->rx.req_prod_pvt = 0;
 
     /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
     for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Applied
#1 lore raw

Applied, thanks. The initialisation of req_prod_pvt wasn't needed at all.

K.

Quoted 15 lines · Dietmar Hahn

Hi Gregor,

attached is a small patch for netfront.c.
A compiler warning is fixed when -O? is used.
If the network is not configured, backend gets NULL from xenbus_read() and this leads sometimes to a crash because this pointer is used later.
I hope this fix is OK. Please have a look and send comments! Thanks.

Dietmar.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel