2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-23 14:57:06 +00:00

Fix bug in parsing large datapath IDs.

Datapath IDs are unsigned, but dpid_from_string() was parsing them as
signed integers, which caused high values to be capped at INT64_MAX.

Also, document that datapath IDs may not be all-zero.

Reported-by: Pankaj Thakkar <thakkar@nicira.com>
Reported-by: Teemu Koponen <koponen@nicira.com>
This commit is contained in:
Ben Pfaff
2010-10-21 10:40:05 -07:00
parent 4b6b46ce8a
commit 093ca5b366
4 changed files with 11 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 Nicira Networks.
* Copyright (c) 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,16 @@
#include <stdlib.h>
#include "ofpbuf.h"
/* Parses 's' as a 16-digit hexadecimal number representing a datapath ID. On
* success stores the dpid into '*dpidp' and returns true, on failure stores 0
* into '*dpidp' and returns false.
*
* Rejects an all-zeros dpid as invalid. */
bool
dpid_from_string(const char *s, uint64_t *dpidp)
{
*dpidp = (strlen(s) == 16 && strspn(s, "0123456789abcdefABCDEF") == 16
? strtoll(s, NULL, 16)
? strtoull(s, NULL, 16)
: 0);
return *dpidp != 0;
}